+ 2
x=9 x%=2 x+=3 print(x)
I don’t get what’s going on here I tried for like 10 minutes all I know is the answer is 4 but I don’t understand the equation
51 Respuestas
+ 18
x=x%2
x=9%2=1
x=1
x=x+3
x=1+3
x=4
+ 5
Dima Melnichuk, "%" is the modulus operator which finds the remainder from dividing the two numbers u specify i.e. dividing the number on the left by the number on the right
+ 5
Dima Melnichuk, x = 9 assigns 9 to x. So x %= 2 or x = x % 2 is actually x = 9 % 2.
9 % 2 is 1. So, x = 1
So, the value of x is 1
and then u add 3 to it so it becomes 4...
+ 5
Here the value of x is given as 9 initially!
Step 1 : This says u do modulus operation with 2, i.e x = x % 2 (modulus gives u the remainder) hence x = 1.
Step 2 : the x value gets changes in Step 1 now x value is 1
In this Step add x value to 3 i.e x = x + 3, hence x value becomes 4
And finally ur printing that value..
I hope this explanation may help you ☺️
+ 4
The remainder is 1.
9 % 2
----------
The Quotient is 4 and the remainder is 1. Thats how "%" works
If you did x = 9 / 2, x would be 4.5
Weird, isn't it?? ;)
+ 3
x =9
x%=2 // x=x%2
x+=3 // x=x+3
print(x) // it will print 4
+ 3
x%=2 means x=x%2.
We have the value of x here as 9, so on dividing 9 with 2 we get 1. Thus the new value of x becomes 1.
Now, the equation x+=3 means x=x+3.
Previously we had the value of x=1.
Therefore, x=1+3, i.e., 4.
Hope you find this useful!
+ 2
Dima Melnichuk, the x = 9 ASSIGNS 9 to x, meaning that the value of x will be 9
+ 2
Thanks for helping me out man
+ 1
Dima Melnichuk it's called module operator and used for remainder.
+ 1
Look, x%2 returns the REMAINDER of x / 2 (x divided by 2). So that is 1 (obviously). Then, x + 3 is 1 + 3 which is 4.
Note:
x %= 2 means x = x % 2
And x += 3 means x = x + 3
Hope you got ur answer. Thank you. <3
+ 1
What does the x=9 do then
+ 1
Yeah i know that but it the equation of x%=2 where will the 9 go
+ 1
2 times 4 is 8 and you cant do 10 because it is past the number so 9-8 is 1
+ 1
Exactly
+ 1
You are welcome
<3
+ 1
Mind talking in the dm..??
+ 1
x=9
x=x%2 # here x=1
x=x+3 #now x=1+3=4
+ 1
9%2=1
1+3=4
Print (x)
Output:4
+ 1
x=x%2
x=9%2=1
x=1
x=x+3
x=1+3
x=4