+ 1
what does % mean
i think it means percent but in python they gave me this question >>> x = 3 >>> num = 17 >>> print(num % x) and whatever answer i do it says wrong
7 Réponses
+ 4
% for remainder.
______
3 | 17 |5
______
2
answer is 2 because here remainder is 2.
+ 2
me neighter
don't know why this has so many votes, lol 😅
17 = 5*3 + 2
(rest, the number after plus, is called the remainder)
the modulos operator calculates it
17%3 = 2
that's it
+ 1
I dont get this?
______
3 | 17 |5
______
2
0
% gives you the remainder of a division.
13 % 3 == 1
0
it modolo or modulo (not sure how spelled ...)
it means you make a division and the "rest" which is no divisible by the number is left.
exemple:
17%3 = 2
16%3 = 1
15%3 = 0
it has multiple uses such as testing if a number is divisible by another number.
0
fun fact: In Python this also works for floats. Not only for integers.
For example
5.3 % 2.5 = 0.3
(because 5.3 = 2*2.5 + 0.3, i.e. rest of 0.3)
0
This is the modulo operator that returns the remainder of a division. In other languages is might only work for Integers but in Python it also works for floats.
This is a program I wrote that demonstrates the use of modulo in a way other than returning the remainder
https://code.sololearn.com/c3UUKoI2qycu/?ref=app