Created
November 21, 2016 15:00
-
-
Save natmchugh/5bd3e1c9f2df0f438c2c20374aec019f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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