Question in Learn Python 3 -CONTROL FLOW Boolean Operators: not

I’m new to Code Academy and had a question about the syntax in the following lesson:


Why is it necessary to add the parentheses in the following code ?

"if not credits >= 120 and not gpa >= 2.0:
print(“You do not meet either requirement to graduate!”)

Because print() is a function and you’re passing that string as an argument.

Hi lisalisaj,

I was wondering why i needed to add the ( ) this part of the code not including the print statement

"if not (credits >= 120) and not (gpa >= 2.0):

why are the parentheses needed before the c in credits and after the 0 in 120 and then again in before the g in gpa and then after the
0 in 2.0

ah, ok. you weren’t specific.
because you’re comparing two things. booleans only have 2 values: True, False.
The expressions in the parens, or brackets are evaluated first and then “not” negates what is in the parens/reverses the boolean value. Parentheses also make the comparison more easily readable.
Both sides of the expression have to be True and you’ll get the output in the print statement.

If you look at something like this:

not (True and (False or True))

What is the answer?


But why? 

1. False or True is True
2.True and True  is True
3. not True  is False

Which is easier to read than not True and False or True.

1 Like

Thank you so much this make sense to me now.

1 Like

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.