# Simple mathematics game # Player has to answer 10 questions. # Print score after all questions have been answered. # Messages for 6 or fewer correct, 7 or 8 correct, 9 or 10 correct. # No error-checking at this point. import random correct = 0 cor = ("Great!","Good job!","Correct!") inc = ("Sorry.","Sadly no.","Incorrect.") diff = input("Difficulty? (E)asy, (M)edium, (H)ard: ") if diff == "E": high = 12 elif diff == "M": high = 20 else: high = 30 streak = 0 for count in range(1,11): n1 = random.randint(2,high) n2 = random.randint(2,high) operation = random.choice("+-*/") if operation == "+": question = str(n1)+" + "+str(n2) answer = n1+n2 elif operation == "-": question = str(max(n1,n2))+" - "+str(min(n1,n2)) answer = abs(n1-n2) elif operation == "*": question = str(n1)+" * "+str(n2) answer = n1*n2 else: question = str(n1*n2)+" / "+str(n2) answer = n1 prompt = "Question #"+str(count)+": What is "+question+"? " guess = int(input(prompt)) if guess == answer: correct += 1 streak += 1 print(random.choice(cor)) else: streak = 0 print(random.choice(inc)) if streak == 3: print("You're on a streak!") elif streak > 3: print("Keep that streak going!") print("You scored", correct, "out of 10.") if correct <= 6: print("Looks like you need more practice.") elif correct <= 8: print("Not too bad.") else: print("Super!")