FAQ: Control Flow - Boolean Variables

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

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

Computer Science

FAQs on the exercise Boolean Variables

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!

8 posts were split to a new topic: Py print does seem to work? Am I using it wrong?

I apologize, I am still pretty new at this. This is from an example in step 4/12 under ‘Control Flow’ sectino of Python 3. How is bool_one true and bool_two false? 5! is 120, and with the space in between, Python is clearly not performing the calculation. The math checks out in bool_two, but again i understand it is treating the characters as a string and not integers. Is the issue that ‘1 + 1 !’ has invalid syntax and thus cannot be equal to a variable? or is it perhaps that the ‘+’ requires an impossible calculation and thus cannot be equal to a variable? Thank you for your help and please stay safe out there!

bool_one = 5 != 7
bool_two = 1 + 1 != 2

I think you misunderstand the != operator, which means: not equal

5 does not equal 7 → true
2 does not equal 2 → false, these values are equal

! is not a factorial operator here.

1 Like

HA that makes total sense. the space had me weirded out and I could not figure this out for me.

I checked out of curiosity if the exercises (and Python itself, as I checked the outcome of 1 == True) would recognize 1 and 0 as True and False, and they did! Even in step 4, I got away with my_baby_bool_two = 1 and printing its type as <class 'int'> which I suppose shouldn’t be possible if the checker didn’t recognize the digits as bools. So 1 kind of is an int and a bool at the same time?

This raises the question, are there some important caveats to using 1 and 0 this way? Is it bad practice to have Python coerce these digits into bool when needed, as seen when using 1 in a boolean expression?

I may be wrong, but there was no proper introduction to type() ahead of this lesson. So when prompted to print the type, it was rather confusing!

1 Like

Agreed, that being said it’s quite simple; print(type(my_variable)) should do the job.

Immediately when starting executing this exercise I wrote my_baby_bool = True, which is correct, to then understand that I was forced to make it ‘‘wrong’’, set it as a string and write with a small letter to then be told that it is wrong. Rather mechanic and frustrating way to teach but I see the point.

I do not manage to activate next, in order to go on with the lesson