Conditionals & Flow exercise 6. I NEED AN EXPLANATION PLEASE


#1

Hello lads and gals,

i am having big time trouble with understanding exercise no.6 in this chapter. i can do the math correctly but i cannot understand the correct code and why when i hit ‘Get Code’ it gives me this:
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

My logic:

bool_one -> False
bool_two -> False (2 == -2 is false)
bool_three -> False (3 != 3 is false)
bool_four -> -(1 ** 2) < 2 ** 0 => -1 < 1 which is True
-> 10 % 10 <= 20 - 10 * 2 => 0 <= -80 which is false , so bool_four is False
bool_five -> True

After i Print all five bools it gives me this:

False
False
False
True
True

can anyone explain the logics of this exercise please?
thank you!


#2

so, if i understand correctly you understand all correctly except bool_four?

The purpose of the exercise is to manually evaluate the condition, and then set the bool accordingly, so for bool_one this would be false:

bool_one = False

get code gives:

bool_one = False and False

that shouldn’t be, i will look into it

of bool_four, i think you got the math wrong here:

10 % 10 <= 20 - 10 * 2

the modulo operator (%) and multiply (*) should be done first (order of operations), so we :

0 <= 20 - 20

which result in:

0 <= 0

which is true


#3

i didn’t see the 10 * 2 and mistook it with 10 ** 2. Cheers mate! thank you a lot for opening my eyes! :smiley:


#4

most people get stuck at the modulo operator (10%10 is 0, while 10/10 is 1)

multiplying or exponent is quit a difference, so all good now?


#5

yup all good! thank you :slight_smile:


#6