I'm creating a basic game that tests you on your times table. You are under a timer and your score is counted up and displayed at the end.
I can either get the game to run or the timer, but not at the same time. As in to play the game for 30 sec then the game ends.
import time
import random
yn = raw_input("Do you wanna play? y/n ")
#passed_time = 0
if yn == "n":
exit()
else:
timer= raw_input ("type start to begin the 30 sec timer -- ")
num1 =int( random.choice(range(1,13))) #generating random numbers
num2 =int( random.choice(range(1,13)))
a = str(num1) #turning into a string for text print
b = str(num2)
#score = 0
real_answer = num1 * num2
print "What is " + a + " x " + b + "?"
user_answer = int(raw_input("answer "))
while user_answer != real_answer:
print "You are wrong, try again "
user_answer = int(raw_input("Try again- "))
if timer == ("start"):
seconds = 5 ##how long the timer should be set to
for i in range (seconds):
time.sleep(1)
print ("time is up")
I would like the program to run for 30 seconds then stop and display results.