import random def generateNumber(): return random.randrange(-50, 50) def askQuestion(n1, n2): question = "What is " + str(n1) + " + " + str(n2) + "?" input = raw_input(question) return input def report(good, total): print "Thanks for playing, you got", good, "correct out of", total def main(): limit = 10 (good, total) = (0, 0) while limit > 0: n1 = generateNumber() n2 = generateNumber() answer = askQuestion(n1, n2) if answer == 'quit': break elif answer == 'hard': continue else: if int(answer) == n1 + n2: (good, total) = (good + 1, total + 1) else: total += 1 limit = limit - 1 report(good, total) main()