Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import time, random, sys
- from tkinter import *
- from threading import Timer
- #Global variables to be set
- global endGame
- global gameTime
- endGame = False
- gameTime = 20
- #functions required throughout the game
- def runTimer(x):
- t = Timer(x,time_up) # x is amount of time in seconds
- t.start()
- mathFunction()
- def time_up():
- print('your time is up!')
- global endGame
- endGame == True
- print (endGame)
- print('your time is up!')
- def mathFunction():
- global endGame
- while endGame == False:
- Int1 = random.randint(0,20)
- Int2 = random.randint(0,20)
- Int3 = random.randint(0,20)
- if Int1 > Int2:
- answer = (Int1 - Int2) * Int3
- print ('(',Int1,'-',Int2,') x ',Int3)
- elif Int2 > Int1:
- answer = (Int2 - Int1) * Int3
- print ('(',Int2,'-',Int1,') x ',Int3)
- userInput = 0
- while True:
- try:
- userInput = int(input("Enter your answer: "))
- except ValueError:
- print("Not an integer!")
- continue
- else:
- if userInput == answer:
- print('Correct')
- break
- else:
- print('Wrong')
- break
- #Display the first input as to whether the player would like to play
- choice = ""
- while choice != "n":
- choice = str(input('Would you like to play?(y/n)'))
- if choice == 'y':
- runTimer(20)
- while endGame == False:
- mathFunction()
- elif choice == 'n':
- break
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement