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", reportScore(good, total) def reportScore(good, total): print good, "out of", total, def main(): limit = 10 (good, total) = (0, 0) while limit > 0: reportScore(good, total) n1 = generateNumber() n2 = generateNumber() answer = askQuestion(n1, n2) if answer == 'quit': break elif answer == 'hard': continue else: if int(answer) == n1 + n2: print "Very good." (good, total) = (good + 1, total + 1) else: print "Wrong, the correct answer was:", (n1+n2) total += 1 limit = limit - 1 report(good, total) main()