FAQ: Learn Python - Conditionals & Control Flow - And

This community-built FAQ covers the “And” exercise in Codecademy’s lessons on Python.

FAQs for the Codecademy Python exercise And:

Join the Discussion. We Want to Hear From You!

Have a new question or can answer someone else’s? Reply (reply) to an existing thread!

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

Need broader help or resources about Python in general? Go here!

Want to take the conversation in a totally different direction? Join our wider discussions.

Learn more about how to use this guide.

Found a bug? Report it!

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

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

Other FAQs

The following are links to additional questions that our community has asked about this exercise:

  • This list will contain other frequently asked questions that aren’t quite as popular as the ones above.
  • Currently there have not been enough questions asked and answered about this exercise to populate this FAQ section.
  • This FAQ is built and maintained by you, the Codecademy community – help yourself and other learners like you by contributing!

Not seeing your question? It may still have been asked before – try (search) in the top-right of this page. Still can’t find it? Ask it below by hitting the reply button below this post (reply).

I have no idea what to type into the editor for this “And” practice. The Hint doesn’t help out in any way either. I understand math equations and can work out if an equation is true or false, but what am I supposed to type in the editor after each variable? Is this just an exercise in cut, copy, and paste?

Am I supposed to define the ‘bool_one’ variable as:
bool_one = False and False

or am I supposed to make up an equation? I’m clearly not understanding this whole line of exercises.

4 Likes

No, we are supposed to visually/mentally evaluate that expression and supply what we believe the outcome to be.

False and False

will be False since we know that AND short-circuits on false. Only the first operand is evaluated in this case. We are given mental exercises like this so we gain instant recognition of things like that, and are able to do it in our head.

1 Like

I agree with Brave - I had no idea what to do here. And I’m not sure that mtf’s answer is correct… I had to go to “solution” which is just to type exactly what’s in the instructions. I’m not sure how that helps me learn it. But I’m new so who knows. :slight_smile:

3 Likes

I agree with gthill, it’s unclear what is required, I tried what mtf suggested and it didn’t work, so in the end I used the solution button and it was a copy paste situation. Baffling.

For the record, I did not give a solution. We are given expressions to visually examine and evaluate in our heads. Look at it, break it down, first the left operand, then the right (if needs be).

Keep in mind that if the first operand is False then we need not continue evaluating. We’re done. The expression is False. If the first operand is True, then evaluate the second. If it is False then the expression is False, else True.

Do this in your head. That’s the bottom line.

1 Like

Am I on glue or have I forgotten my basic algebraic functions? The problem presented in bool_4 is
-(1 ** 2) < 2 ** 0 and 10 % 10 <= 20 - 10 * 2
According to my calculations -1 < 1 and 1 >= 0 which renders the answers true and false, making the expression overall false.
I’ve gotten the solution and will move forward in the lesson but I know this is going to bug me… Can someone point out where I’m going wrong?

The goal here is not so much True or False, but truthy or falsy which round out as true or false.

-(1 ** 2)

Order of operations puts brackets first, so we must evaluate what’s inside them, to start.

1 ** 2  =>  1

So now we have -(1). Multiplication is distributive over addition, so we can multiply the contents of the brackets by -1 to arrive at,

-1

Now, 2 ** 0 is 1, so you have first relationship evaluated correctly.

-1 < 1  => truthy

On to the second operand,

10 % 10  =>  0

20 - 10 * 2  =>  20 - 20  =>  0

Note that order of operations put multiplication first, then addition.

Zero is less than or equal to zero, so that expression is also truthy.

truthy and truthy  =>  True

Thank you! I must have misunderstood- % is not the symbol indicating division?

1 Like

It is the symbol for REMAINDER in Euclidean Division.

D = dq + R

where R is the remainder, or modulo of the division, and where q is an integer.

The computer calculates all remainders, so the modulo need not be an integer.

3.14 % 2  =>  1.14
1 Like

I appreciate your help!

1 Like

I think the main issue people in this thread are having is not related to the maths. I was having the same issue, not quite understanding what the task wanted me to do. I eventually figured out the issue was with capitalisation of the ‘True’ or ‘False’ answers. I had been using lower case words; hence, the software was telling me I was incorrect. Hope this helps anyone else with same issue!

I think the rub is in the counterintuive meaning of % in python as in 10 % 10. This expression returns the reminder of the division of 10 by 10, which is 0.

Yeah, it’s really unclear what we were supposed to do here… i also came here to figure it out.
Tip: make sure True/False are capitalized also, or it will be interpreted as a variable and give an error message