FAQ: Control Flow - Boolean Operators: and


#1

This community-built FAQ covers the “Boolean Operators: and” exercise from the lesson “Control Flow”.

Paths and Courses
This exercise can be found in the following Codecademy content:

Computer Science
Data Science

FAQs on the exercise Boolean Operators: and

Join the Discussion. Help a fellow learner on their journey.

Ask or answer a question about this exercise by clicking reply (reply) below!

Agree with a comment or answer? Like (like) to up-vote the contribution!

Need broader help or resources? Head here.

Looking for motivation to keep learning? Join our wider discussions.

Learn more about how to use this guide.

Found a bug? Report it!

Have a question about your account or billing? Reach out to our customer support team!

None of the above? Find out where to ask other questions here!


#2

Hi,

I’m stuck on exercise 1. Statement two is only showing py (4 * 2

I’ve reported the missing expression, but what does “py” mean in this context? The expression listed for Statement one is also preceded by “py”.


#3

Nothing special. py is the extension used on Python files but I’ve never seen it have any special meaning in code context. Could be a typo or something wonky with the page composer on the backend.


#4

I have also seen this happen to me just now. It seems like the instructions code has a slight typo that needs to be fixed. I just skipped to the solution so I could continue.


#5

statement_one = True and False

statement_two = True and True

For other people that don’t want to skip the entire exercise you can use booleans to bypass that particular step since yeah, the expressions are broken currently.


#6

I am stuck on step 2. I complete step 1 by making statement_one and statement_two equal to the provided expressions. When I try to do step 2, though, my function is exactly the same as the solution, but it won’t give me the appropriate return until I change the statement_one and statement_two to equal False and True. Can anyone explain what those two statements have to do with the step 2 function?


#7

If you are doing this,

statement_one = (2 + 2 + 2 >= 6) and (-1 * -1 < 0)

statement_two = (4 * 2 <= 8) and (7 - 1 == 6)

Then Reset and start over. That is not what we are expected to do. This is a thought process exercise.

In our heads we should be able to examine each operand and evaluate…

(2 + 2 + 2 >= 6)  =>  True, or False?  T  |
=>                                    and |  False
(-1 * -1 < 0)     =>  True, or False?  F  |

(4 * 2 <= 8)      =>  True, or False?  T  |
=>                                    and |  True
(7 - 1 == 6)      =>  True, or False?  T  |

#8

Thank you, I get that portion now, but for step two, even when I set statement_one = False and statement _two = True, I still get the same error. I literally copy and pasted the solution, which was exactly the same as what I had written and when I copy and pasted the solution it worked, but with what I had written it didn’t. Is there something I’m missing.


#9

Is this the code?

def graduation_reqs(gpa, credits):
  if gpa >= 2.0 and credits >= 120:
    return "You meet the requirements to graduate!"

#10

Yes. When I type that in it marks the step with an X and I get the statement "Expected graduation_reqs() with test values gpa = 2.0 and credits = 120 to return “You meet the requirements to graduate!”

I copy and paste it from the solution, it’s marked with a check even though they both say exactly the same thing.

This is what I typed:
def graduation_reqs(gpa, credits):
if (gpa >= 2.0) and (credits >= 120):
return “You have enough credits to graduate!”

This is the provided solution:
def graduation_reqs(gpa, credits):
if (gpa >= 2.0) and (credits >= 120):
return “You meet the requirements to graduate!”


#11

Hah nevermind, I see what I missed. The return statement. Well I feel like a dummy now. Thank you for helping!


#12

You’re welcome! Lesson here? Read and follow instructions closely.

Since we are not grouping operations, no parens are needed.

if gpa >= 2.0 and credits >= 120

The relationship operators have precedence over AND, so those operations are carried out first.


#13

The way I see it you need to call the function as follow:

def graduation_reqs(credits, gpa):
  if credits >= 120 and gpa >= 2.0:
    return "You meet the requirements to graduate!"

print(graduation_reqs(120, 2.0))

or add print to the return statement in the function then call the function:

def graduation_reqs(credits, gpa):
  if credits >= 120 and gpa >= 2.0:
    return print("You meet the requirements to graduate!")

graduation_reqs(120, 2.0)