Stuck with bool_four please help


#1



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


Error in calculation of bool_four, window pops up saying :" double check your value for bool_four"


To get the exercise right


 bool_one = 1 > 2 and 4 > 5

bool_two = 2 == -2 and 4 >= 4

bool_three = 4.75 == 3 and 67 == 68

bool_four = -1 < 1 and 1 <= 0

bool_five = 2 == 2 and 26 < 30


#2

Instruction:

Set bool_four equal to the result of -(1**2) < 2**0 and 10 % 10 <= 20 - 10 * 2

so will it be True or False ?

set the result to bool_four


#3

I guess it should be False but i don't understand how my code is supposed to look like


#4

can you please elaborate it?how?

if the result is True then set bool_four True

bool_four = True

if the result is False then set bool_four False

bool_four = False


#5

I edited the previous post, i don't get how i'm supposed to type the code in, bool_four is given as:
-(1**2) < 2**0 and 10 % 10 <= 20 - 10 * 2 so it becomes -1 < 1 and 1 <= 0 but i don't get what i'm supposed to type after bool_four =


#6

I got it finally, i thought i was supposed to type in the result of the calculation insteadof just True or False


#7

did you understand?

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

The lesson wants first understand the result of it then set it to bool_four


#8

I guess it's true because it calculates without giving the priority to the * so instead of calculating 20 - ( 10 * 2 ) wich would make bool_four False it calculates 20 - 10 and then 10 * 2 therefore 10 % 10 <= 20 - 10 * 2 is True. Am i right?


#9

Anything in brackets is done first.
and Multiplication comes before Subtraction

so 20 - 10 * 2 becomes 20-20 then 0
therefore 10 % 10 <= 20 - 10 * 2 becomes
0<=0 (True)
see this Operator precedence rule in Python


#10

I'll check it out, what i meant is that i was calculating as if there were brackets so i was getting it wrong so when i saw 20 - 10 * 2 i calculated it as 20 - (10 * 2 ) so i got the result 1 <= 0 wich is False but the correct way was to calculate 20 - 10 * 2 --> 10 * 2 --> 20 so we have 1 <= 20 wich is True and also the correct answer


#11

p.s. by the way thanks for the replies , i just started on codeacademy yesterday and it's nice to get some help


#12

p=10 % 10
print p

it'll be 0 not 1
why dont you try every single part like this ?you'll understand everything :slight_smile:


#13

Thanks for the tip, i'll try the way you said! (thought 10 % 10 would return 1 ... sorry i'm a total noob :joy: )


#14

most welcome :slight_smile:

At first you should know how does % work ?
see this how does % work


#15

I confused % with / , i should be ashamed of myself :disappointed_relieved:


#16

you shouldn't be :slight_smile:

see Remainders(aka modulo( % ))


#17

Thanks for all the help, i'll let you know when i get stuck again :grin:


#18

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