Conditional and Control Flow Help


#1



https://www.codecademy.com/courses/python-beginner-BxUFN/2/2?curriculum_id=4f89dab3d788890003000096#

File "python", line 5
bool_three = 19 % 4 != 300 / 10 / 10 and False
^
SyntaxError: invalid syntax

I'm not sure. I'm having trouble understanding the objective in the lesson.


bool_one = False and False

bool_two = -(-(-(-(-2))) == -2 and 4 <= 16**0.5

bool_three = 19 % 4 != 300 / 10 / 10 and False

bool_four = -(1**2) < 2**0 and 10% 10 <= 20 - 10 * 2

bool_five = True and True


#2

In the instructions, you need to write the result to the answers in equations/questions given.

Example for the 2nd variable: Set bool_two equal to the result of -(-(-(-2))) == -2 and 4 >= 16**0.5

Well, lets do the first half of the equation.:slight_smile:

-(-(-(-2))) is 2 because you keep - ing it so it's like you're reversing the value of it based on the amount of negative signs (-) after the (-2).
And in the 2nd part of the equation before and:
== -2 , here, we check if 2 is equal (==) to -2. so this is what it looks like so far: 2 == -2
Is it True or False? Do you get it so far? If not, let me know :slight_smile:


#3

Thanks for your help! Unfortunately, I still don't get it.

I see that 2 == -2 is False

Am I supposed to do the math and type the following in line 3?

bool_two = 2 == -2 is False

Also, why is
bool_one = False and False
and
bool_five = True and True


#4

No, you don't need to type the math , just type False.

Let's do the 2nd half of the bool_two equation (continuing from my first post) so you can get an idea of how it works and what your full answer should look like for this variable.

and 4 >= 16 ** 0.5

lets ignore and for now and work through the problem.

4 >= 16 ** 0.5

We first begin working with the equation: 16 ** 5. The square root (**) of 16 is 4, so what we have left is:

4 >= 4 #is four greater or equal ( >=) to 4? Yes it is, so we write True

our full answer should be:

bool_two = False and True

And now we brought and back into the variable above.

For questions in the instructions like:

Set bool_three equal to the result of 19 % 4 != 300 / 10 / 10 and False

We work with the first half of the equation (before the and), and then the other side, to check if its True or False.

And in questions like:

Set bool_five equal to the result of True and True

They're asking us to write our own equation -two equations of our own, actually- and separate both of those equations with the boolean operator and.
If you want to do this math using a calculator, you can go on a code editor and put your equation there, but it's good practice trying to solve them in your head or on a piece of paper yourself. :slight_smile:
Does this help? Let me know if you understand :smiley:.


#5

I did it! I just didn't realize that I had to calculate the math. I thought the program was supposed to the values on either side of the operator.

Thanks for your help!


#6

No problem! :smile: Happy coding!


#7

I have a question on bool_four.

First half is -(1**2) < 2**0 = -1<1 (True); Understood.

The second half is 10 % 10 <= 20 - 10 * 2

If I follow order of operations, I would get 1 <= 0 (False). But the answer seems to work sequentially rather than mathematically and gives 1 <= 20 (True).

Does all code with python work sequentially rather than via standard order of operations or am I missing something else?


#8

Oh. % is the remainder only rather than the division! That makes a lot more sense. Sorry!


#9

help me with this code. this is for the problem mentioned in the conditional and control flow section for python:

Set this to True if 17 < 328 or to False if it is not.

if 17<328 :
bool_one = True # We did this one for you!
else:
bool_one = False

Set this to True if 100 == (2 * 50) or to False otherwise.

if 100==(2*50) :
bool_two = True
else:
bool_two = False

Set this to True if 19 <= 19 or to False if it is not.

if 19<=19:
bool_three = True
else:
bool_three = False

Set this to True if -22 >= -18 or to False if it is not.

if -22>=-18:
bool_four = True
else:
bool_four = False

Set this to True if 99 != (98 + 1) or to False otherwise.

if 99!=(98+1):
bool_five = True
else:
bool_five = False


#10

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