I am an amateur python coder and i was wondering if it is possible to put a timer into my times table game and if possible where i could put it. Here's my code for my game help would be appreciated , thanks :)
import random
import time
print ("Hello , this is the mental maths game")
time.sleep(0.25)
print ("You will have to answer 50 questions on each different level and get 45 or more correct to proceed")
name = input("What is your name?")
print ("Okey, ",name," lets begin.")
difficulty = "bronze"
correct_answer = 0
points = 0
def get_int(prompt=""):
while True:
try:
return int(input(prompt))
except ValueError:
print("Try again, value entered was not an integer.")
if difficulty == "bronze":
questions = 50
while questions > 0:
x = random.randint(1,8)
y = random.randint(1,8)
answer = (x * y)
print ("What is ",x ," x ",y)
guess = get_int()
if guess == answer:
print ("Correct.")
time.sleep(0.25)
correct_answer = correct_answer + 1
questions = questions - 1
points = points + 5
else:
print ("incorrect")
time.sleep(0.25)
questions = questions - 1
time.sleep(0.25)
print ("You got ",correct_answer," questions correct. ")
time.sleep(0.25)
if correct_answer >= 45:
print ("You may proceed to the next round")
difficulty = "silver"
points = points + 250
else:
print ("Unlucky you didn't get to the next round you were ",45 - correct_answer," answers short of passing.")
time.sleep(0.25)
print ("You scored ",points," points!")
time.sleep(0.25)
print ("Thanks for playing!")
correct_answer = 0
if difficulty == "silver":
questions = 50
while questions > 0:
x = random.randint(6,15)
y = random.randint(5,13)
answer = (x * y)
print ("What is ",x ," x ",y)
guess = get_int()
if guess == answer:
print ("Correct.")
time.sleep(0.25)
correct_answer = correct_answer + 1
questions = questions - 1
points = points + 10
else:
print ("incorrect")
time.sleep(0.25)
questions = questions - 1
time.sleep(0.25)
print ("You got ",correct_answer," questions correct. ")
time.sleep(0.25)
if correct_answer >= 45:
print ("You may proceed to the final round. Good luck!")
difficulty = "gold"
points = points + 750
else:
print ("Unlucky. You failed to get to the last round you were",45 - correct_answer," answers short of passing.")
time.sleep(0.25)
print ("You scored ",points," points!")
time.sleep(0.25)
print ("Thanks for playing")
correct_answer = 0
if difficulty == "gold":
questions = 50
print("WARNING! THIS LEVEL IS EXTREMELY HARD YOU MUST ANSWER ALL 50 QUESTIONS CORRECT!")
while questions > 0:
x = random.randint(11,20)
y = random.randint(11,18)
answer = (x * y)
print ("What is ",x ," x ",y)
guess = get_int()
if guess == answer:
print ("Correct.")
time.sleep(0.25)
correct_answer = correct_answer + 1
questions = questions - 1
points = points + 25
else:
print ("incorrect")
time.sleep(0.25)
questions = questions - 1
time.sleep(0.25)
print ("You got ",correct_answer," questions correct. ")
time.sleep(0.25)
if correct_answer == 50:
points = points + 2500
print("Congratulations, you completed the game with ",points," points!")
if points == 6000:
print("You've unlocked the bonus round because you scored FULL POINTS! Lets see how much of a maths master you really are!")
difficulty = "platinum"
else:
print ("You didn't manage to complete the last level of the game you were",50 - correct_answer," answers short of passing.")
time.sleep(0.25)
print ("You scored ",points," points!")
if difficulty == "platinum":
questions = 50
print("WARNING! THIS LEVEL IS HARRDER THAN EXTREMELY HARD AND YOU NEED ALL 50 QUESTIONS RIGHT AGAIN BUT YOU GET ALOT OF POINTS REMIND ME AGAIN WHY AM I USINGS CAPS? OH WELL GOOD LUCK!")
while questions > 0:
x = random.randint(15,25)
y = random.randint(15,25)
answer = (x * y)
print ("What is ",x ," x ",y)
guess = get_int()
if guess == answer:
print ("Correct.")
time.sleep(0.25)
correct_answer = correct_answer + 1
questions = questions - 1
points = points + 50
else:
print ("incorrect")
time.sleep(0.25)
questions = questions - 1
time.sleep(0.25)
print ("You got ",correct_answer," questions correct. ")
time.sleep(0.25)
if correct_answer == 50:
points = points + 5000
print("Congratulations, you completed the game (for real this time) with ",points," points!")
else:
print ("You failed to complete the game (For real) but you got ",points," points!")
time.sleep(0.25)
print ("You failed to complete the game (For real) with ",50 - correct_answer," answers short of completing the game (For real).")