+ 2
what is %
4 ответов
+ 3
modulo. it gives you the remainder after dividing
example:
num = 10
remainder = num%2
# remainder is zero
print("The number 10 is even")
num = 11
remainder = num%2
#remainder is one
print("The number 11 is odd")
+ 1
modulu
+ 1
better yet,
numIn = input("Please enter a number: ")
if numIn%2 == 0
print("The number you entered is even")
else
print("The number you entered is odd")
note: I trust the user to insert an integer, because I skipped error handling. this is simplest example to show modulo. can be very powerful. :)
+ 1
I get it thanks