+ 1
How to calculate this7%(5//2)?
Python code
6 odpowiedzi
+ 2
We first calculate the code inside the parentheses, 5 // 2. This returns 2(because 5 // 2 is equal to 2 with a remainder of 1). After doing this, we can get the modular value of 7 % 2, which returns the remainder of 7 / 2. This means the answer is 1, as 7 / 2 is 3 with a remainder of 1.
+ 2
Deepanshu Verma
7%2=1 because the result of a % b must always be less than b, but non-negative.
The result must also be a - n * b, (n is any whole number)
There always exists only 1 possibility for a - n * b, which is less than b, but non-negative.
We'll get an equation:
2 > 7 % 2 >= 0
Change a % b to a - n * b:
2 > 7 - n * 2 >= 0
Dividing all 3 sides by 2:
1 > 3.5 - n >= 0
Subtracting 3.5 from all sides:
-2.5 > -n >= -3.5
Multiplying by -1 (arrows will change direction):
2.5 < n <= 3.5
Because n must be whole number, it must be 3, because only whole number between 2.5 and 3.5 is 3.
We'll put n in a - n * b formula:
7 - 3 * 2 = 7 - 6 = 1
We got 1.
Maybe too complicated, but I like mathematical proving.
0
5//2 = 2 -> // rounds it to floor value
7%2 = 1
0
How 7%2=1comes?
0
Remainder of the division
0
Your tag 'float' makes no sense - your question is not about floats.
Can you change it to something more fitting?