Skip to content

Instantly share code, notes, and snippets.

@MrDMurray
Created October 19, 2016 18:58
Show Gist options
  • Save MrDMurray/69061dc344c13d3f959a4b3bf6b801f4 to your computer and use it in GitHub Desktop.
Save MrDMurray/69061dc344c13d3f959a4b3bf6b801f4 to your computer and use it in GitHub Desktop.
Does is divide evenly? Using a Modulo (Remainder)
# / means divide
# 10/2 is ten divided by 2
# 10/2 = 5
# % means remainder
# 10%2 is how much is left over (remainder) when 10
# is divided by 2.
# 10%2 = 0
if 6%2 == 0:
print("Yay, 6 divided by 2 has zero remainder")
else:
print("Boo")
#this will play the first one because there is no remainder
if 6%5 == 0:
print("Yay, 6 divided by 2 has zero remainder")
else:
print("Boo, 6 divided by 5 has a remainder")
#this will play Boo because 5 doesn't go into 6 evenly.
# A program to check if a number is even would look like this:
number=float(input("Enter a number and I'll say if it's even"))
if number%2 == 0:
print("Aye! This be even beyond beleve'n")
else:
print("Nay! This isn't even even Steven")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment