0

I don't get how % work like in X=9 X%=2 Print (X) It shows 1 Like how?

10th Nov 2022, 8:33 AM
Hi Ba
Hi Ba - avatar
14 Antworten
+ 6
Hi Ba In modulus operator its divide with whole positive number which is 4 in case of 9 % 2 So 2 * 4 + 1 = 9 So here 1 is a reminder value 9 / 2 = 4.5 9 // 2 = 4 9 % 2 = 1
10th Nov 2022, 9:39 AM
A͢J
A͢J - avatar
+ 7
Hi Ba % --->it is a modulo operator which gives remainder... So 9%2 gives 1 as remainder Read the lessons in python beginners..
10th Nov 2022, 8:36 AM
Riya
Riya - avatar
+ 4
9 divided by 2 ---> remainder 1
10th Nov 2022, 8:42 AM
Riya
Riya - avatar
+ 2
Hi Ba % means we have to find remainder in Python. For example 9%2=4*2+1 so here 1 is remainder, 4 is result which we get when we divide 9 by 2 .
10th Nov 2022, 5:31 PM
Avinash
Avinash - avatar
+ 2
Hi Ba You are trying to solve for the remainder value so think of it as long division. How many times does 2 go into 9? 4 times, which would be 8. Then you take 9 - 8 which gives you your remainder value of 1. You want your remainder value to be an int (a whole number) and not a float (a decimal point).
11th Nov 2022, 3:22 PM
Mason Trumbull
Mason Trumbull - avatar
+ 1
Remainder of what ? And 9%2 is it multiplied or what?
10th Nov 2022, 8:41 AM
Hi Ba
Hi Ba - avatar
+ 1
9 divided by 2 isn't 4,5? from where comes 1? I really don't get it 😅
10th Nov 2022, 8:51 AM
Hi Ba
Hi Ba - avatar
+ 1
The modulo operator evaluates for the closest possible whole number and returns the remainder. The code: X %= 2 Is reassigning the value of x. It can also be written as: X = x % 2 So it stores the new value of x after the modulo operation is completed. Modulo operation is properly explained in the "python for beginners course" .
10th Nov 2022, 10:01 AM
Toymak3r
+ 1
X%=2 is same as x=x%2 9%2=1 .1 is the remainder on dividing 9 by 2
11th Nov 2022, 2:10 PM
KAUSHIK T K
KAUSHIK T K - avatar
0
Because modulo operator gives remainder: 9=2×4+1
11th Nov 2022, 2:38 AM
Sahil Kumar
Sahil Kumar - avatar
0
% shows a division remainder. So 9 : 2 = 4(1 - remainder)
11th Nov 2022, 3:20 PM
ПолинаС
0
% means remainder. So you divide the 9 by2 for 4. But what is left? What does the 2 not divide into? The one, since 9 is odd. So it outputs one. If it were 2/2, % would produce 0, since 2 goes into 2 evenly. It is divided but it only ourputs whatever is
11th Nov 2022, 7:35 PM
AquaNova27
0
It is the remainder of it divided by 2
11th Nov 2022, 11:09 PM
Jensen
Jensen - avatar
0
modulus means division with reminder so when you devide 9 by 2 the result will be 4 and 1 as the reminder and if you devide 8 by 2 the result will be 4 and 0 is the reminder
12th Nov 2022, 2:10 AM
‎Yahya Mohammed Hazazi
‎Yahya Mohammed Hazazi - avatar