Reputation: 15
Takes in a number and indicates if its remainder when divided by 3 is 0, 1, or 2.
My code:
number = int(input("Please enter the number"))
print(number % 3)
How do I test the result of the modulo to determine whether the number is divisible by 3 or not?
Upvotes: 0
Views: 45
Reputation: 402603
Use the if
to test the remainder from the %
operation:
number = int(input("Please enter the number"))
if number % 3: # is true if the remainder is 1 or 2
print('Not divisible')
else:
print('Divisible')
Upvotes: 1