Skip to content

Instantly share code, notes, and snippets.

@natmchugh
Created November 21, 2016 15:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save natmchugh/5bd3e1c9f2df0f438c2c20374aec019f to your computer and use it in GitHub Desktop.
Save natmchugh/5bd3e1c9f2df0f438c2c20374aec019f to your computer and use it in GitHub Desktop.
import random, operator
random.seed()
def get_random_int():
return random.randint(2, 12)
numberOfQs = 10
ops = {"+": operator.add,
"-": operator.sub,
"*": operator.mul,
"%": operator.mod}
op_char = raw_input('enter a operator (+,-,*,%)')
op_func = ops[op_char]
for i in range(1, numberOfQs+1):
a = get_random_int()
b = get_random_int()
print "Question %d)" % (i)
question = "%d %c %d = " % (a, op_char ,b)
while int(raw_input(question)) != op_func(a, b):
print "Nope\n"
print "Correct\n"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment