Don't understand how line 5 is True


#1



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


It says check your bool_three. Since I have it = false, it's basically saying it's true.


It says to set bool_three equal to not 10 % 3 <= 10 % 2. So 10 / 3 = 3.3 and 10 / 2 = 5.
So: 3.3 <= 5 , which is true, 5 is greater than or equal to 3.3.
Not true is false. Except when I set it to false, it gives me an error.


Replace this line with your code.


#2

bool3:

bool_three = not 10 % 3 <= 10 % 2

agree? it is true. % isn't the division operator in python, / is:

bool_three = not 10 / 3 <= 10 / 2

then you would have:

not 3 <= 5

5 is greater then 3, so that is true, but then you have a not keyword, so it is false

% gives you the remainder:

bool_three = not 10 % 3 <= 10 % 2
bool_three not 1 <= 0

1 <= 0 is false, but then you have a not keyword so it is true


#3

The operator is %, which is modulo, not division. Modulo gives you the REMAINDER from the division.

Hence,
10 % 3 = 1 (ten divided by three goes three times with ONE as a remainder)
10 % 2 = 0 (ten is divisible by two, so there is no remainder)

So 10 % 3 <= 10 % 2 is FALSE. Then when you add the "not", it becomes true.


#4

@triplex930,
The % sign is the so called modulo operator sometimes called the remainder operator
From
https://docs.python.org/2.4/ref/binary.html

The % (modulo) operator yields the remainder from the division
of the first argument by the second argument.

The numeric arguments are first converted to a common type.

A zero right argument raises the ZeroDivisionError exception.

The arguments may be floating point numbers,
e.g., 3.14%0.7 equals 0.34 (since 3.14 equals 4*0.7 + 0.34.)

The modulo operator always yields a result with the same sign as its second operand (or zero);

the absolute value of the result is strictly smaller than the absolute value of the second operand

=============================================================

9%3 You read it as nine modulo three is zero, as 9 divided by 3 has NO rest-value.
22%6 You read 22 modulo six is 4, as 22 divided by 6 will leave you with rest-value 4
10%5 You read 10 nodulo five is zero, as 10 divided by 5 will have NO rest-value

=============================================================

You will have look into the precedence-table
https://docs.python.org/2/reference/expressions.html#operator-precedence


#5

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