To shorten the code and eliminate the need for so many "if" statements, use a "while" statement that continues as long as the number correct is less than nine.
import random print ("Can you get nine in a row?") i = [] while len(i) < 9: random1 = (int)(random.randrange(1,13)) random2 = (int)(random.randrange(1,13)) problem = "What is " + (str(random1)) + " times " + (str(random2)) + "?" answer = (random1) * (random2) correctMessage = "Great job! " + (str(random1)) + " times " + (str(random2)) + " equals " + (str(answer)) + "." incorrectMessage = "Keep trying! " + (str(random1)) + " times " + (str(random2)) + " equals " + (str(answer)) + "." print (problem) userAnswer = input("Enter your answer: ") if userAnswer.isdigit() and (int(userAnswer)) == (int(answer)): print (correctMessage) i.append(int(answer)) if len(i) == 1: print ("Great start!") if len(i) == 2: print ("Two in row!") if len(i) == 3: print ("Three in row!") if len(i) == 4: print ("Four in a row!") if len(i) == 5: print ("Five in a row!") if len(i) == 6: print ("Six in row! Getting closer!") if len(i) == 7: print ("Seven in row! You're so close!") if len(i) == 8: print ("Eight in a row! Don't blow it now!") if len(i) == 9: print ("Nine in row! Well done!") elif userAnswer.isdigit() and (int(userAnswer)) != (int(answer)): print (incorrectMessage) i.clear() else: print ("Be sure to enter your response as a whole number using digits.") print ("Now go tell someone you can multiply numbers between 1 and 12!")
Click multiplication.py to download the file. (The download does not appear to work in Chrome).