how would you solve this 11 + 22 % 4
I think it would be 13
11 + (0.22 * 4)
13
If we were to run that through Python as it stands, the interpreter will spit back 13 to us. "Why does it do that?" you might ask. If we were just to input 22 % 4, we would get a returned value of 2. That's because the % operator gives us the remainder if we were to divide 22 by 4. As (22/4) gives us 5 with a remainder of 2, a returned value of 2 seems perfectly valid here. 11 + 2 = 13 If you wanted to group the problem differently, we'd need to use parentheses. Perhaps we want to know the remainder if we divide the sum of 11 and 22 by 4. Then we'd need to input (11 + 22) % 4. We evaluate the parentheses before division. As 11 + 22 yields 33. We would then divide 33 by 4, getting the result 8 with a remainder of 1. Therefore, python would return 1.
OMG VirPriscus you actually explained the stupid % in a way that I could understand and actually now use. Thank you, even though this wasn't my question you responded to. I have just been surfing other people's questions to see if perhaps the answer I was looking for was already out there. THANKS.
Join our real-time social learning platform and learn together with your friends!