-
Notifications
You must be signed in to change notification settings - Fork 0
/
mathQuiz.py
79 lines (63 loc) · 1.67 KB
/
mathQuiz.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
"""
@Author: Robert Greenslade
@
@Title: Math Quiz
@
@Date: January 10th, 2022
"""
# imports
import datetime
import random
import tkinter
from tkinter.constants import CENTER
# Initialize GUI
gui = tkinter.Tk(screenName='Math Quiz @RobbieG15')
gui.geometry('1000x1000')
gui.configure(bg='black')
# Functions
def startGame():
pass
# Adding Buttons
startButton = tkinter.Button(gui, text='Start', width=10, height=3, command=startGame)
startButton.place(relx=.5, rely=.5, anchor=CENTER)
# Game Logic
def gameInCMD():
operations = ['+', '-', 'x']
correct = 0
incorrect = 0
start = datetime.datetime.now()
limit = 30
x = 0
while x < 100:
pairs = [random.randint(0,12), random.randint(0,12)]
num1 = pairs[0]
num2 = pairs[1]
operator = random.randint(0,2)
if operator == 0:
answer = num1 + num2
elif operator == 1:
answer = num1 - num2
else:
answer = num1 * num2
input1 = input(str(num1) + ' ' + operations[operator] + ' ' + str(num2) + ' = ')
try:
if answer == int(input1):
correct += 1
print('correct')
else:
incorrect += 1
print('incorrect')
except:
incorrect += 1
print('incorrect')
elapsedTime = (datetime.datetime.now()-start).seconds
if elapsedTime > limit:
print("Time is up")
break
x += 1
print('Correct: ' + str(correct))
print('Incorrect: ' + str(incorrect))
return correct, incorrect
gameInCMD()
# Main Loop
gui.mainloop()