forked from github/CopilotForXcode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnew2
110 lines (73 loc) · 3.02 KB
/
new2
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
from tkinter import *
from random import randint,choice
root = Tk()
root.geometry("600x500")
root.title("Maths Quiz")
question = StringVar()
answer = StringVar()
givenAnswer = StringVar()
score = IntVar()
questionNumber = IntVar()
def generateQuestion():
global questionLabel
questionNumber.set(questionNumber.get() + 1)
number1 = randint(1 , 10)
number2 = randint(1 , 10)
operator = choice(['+' , '-' , '*' , '/'])
question.set(str(number1) + operator + str(number2))
answer.set(eval(question.get()))
if questionLabel:
questionLabel.destroy()
questionLabel = Label(root , text=f"Question : {question.get()}" , font=('arial' , 20))
questionLabel.grid(row=2 , column=0)
def checkAnswer():
global scoreLabel
if questionNumber.get() > 10 :
return
global resultLabel
if resultLabel:
resultLabel.destroy()
if str(answer.get()) == givenAnswer.get():
score.set(score.get() + 1)
resultLabel = Label(root , text="Correct" , font=('arial' , 20), fg="green")
resultLabel.grid(row=4 , column=0)
scoreLabel = Label(root , text=f"Score : {score.get()}" , font=('arial' , 20) , fg="black")
scoreLabel.grid(row=5 , column=0)
else:
resultLabel = Label(root , text="Incorrect" , font=('arial' , 20) , fg="red")
resultLabel.grid(row=4 , column=0)
if questionNumber.get() == 10:
scoreLabel.destroy()
scoreLabel = Label(root , text=f"Final Score : {score.get()}" , font=('arial' , 20) , fg="black")
scoreLabel.grid(row=5 , column=0)
else:
generateQuestion()
def restart():
global scoreLabel
scoreLabel.destroy()
score.set(0)
questionNumber.set(0)
generateQuestion()
scoreLabel = Label(root , text=f"Score : {score.get()}" , font=('arial' , 20) , fg="black")
scoreLabel.grid(row=5 , column=0)
# User Interface
headingLabel = Label(root , text="Maths Quiz" , font=('arial' , 25) )
headingLabel.grid(row=0 , column=0)
questionScale = Scale(root , from_=0 , to=10 , orient=HORIZONTAL , length=400, variable=questionNumber)
questionScale.grid(row=1 , column=0)
completeQuestionLabel = Label(root , text="10th question")
completeQuestionLabel.grid(row=1 , column=1)
questionLabel = Label(root , text=question.get() , font=('arial' , 20))
questionLabel.grid(row=2 , column=0)
answerEntry = Entry(root , textvariable=givenAnswer , font=('arial' , 20), width=25)
answerEntry.grid(row=3 , column=0)
submitButton = Button(root , text="Submit" , fg="yellow", bg="grey", font=('arial' , 15) , command=checkAnswer)
submitButton.grid(row=3 , column=1)
resultLabel = Label(root , text="Result" , font=('arial' , 20) , fg="blue")
resultLabel.grid(row=4 , column=0)
scoreLabel = Label(root , text=f"Score : {score.get()}" , font=('arial' , 20) , fg="black")
scoreLabel.grid(row=5 , column=0)
submitButton = Button(root , text="Restart" , fg="red", font=('arial' , 15), width=35 , command=restart)
submitButton.grid(row=6 , column=0)
generateQuestion()
root.mainloop()