-
Notifications
You must be signed in to change notification settings - Fork 1
/
math_solver.py
74 lines (58 loc) · 2.13 KB
/
math_solver.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
from kivy.core.text import LabelBase
from kivy.uix.screenmanager import ScreenManager, NoTransition
from kivymd.app import MDApp
from kivy.lang import Builder
from kivy.core.window import Window
from kivy.uix.button import Button
from kivy import *
from kivymd import *
from kivy.properties import ListProperty
Window.size=(350,600)
from kivy.properties import ListProperty
class SignButton(Button):
bg_color=ListProperty([1,1,1,1])
class OptionButton(Button):
bg_color=ListProperty([1,1,1,1])
class MathSolver(MDApp):
selected_sign=""
answer=""
def build(self):
global screen_manager
screen_manager= ScreenManager(transition=NoTransition())
screen_manager.add_widget(Builder.load_file("start.kv"))
screen_manager.add_widget(Builder.load_file("select_sign.kv"))
screen_manager.add_widget(Builder.load_file("quiz.kv"))
#screen_manager.add_widget(Builder.load_file("final_score.kv"))
return screen_manager
def select_sign(self,sign):
self.selected_sign=sign
num1=random.randint(1,10)
num2=random.randint(1,10)
screen_manager.get_screen("quiz").ids.question.text=f"{num1} {sign} {num2}= ?"
if sign=="+":
self.answer=str(num1+num2)
elif sign=="-":
self.answer=str(num1-num2)
elif sign=="*":
self.answer=str(num1*num2)
elif sign=="/":
self.answer=str(num1/num2)
while option_len<4:
if sign=="+":
option=str(random.randint(1,20))
elif sign=="-":
option=str(random.randint(-10,10))
elif sign=="*":
option=str(random.randint(1,20))
elif sign=="/":
option=str(random.randint(1,20))
if option not in option_list:
option_list.append(option)
else:
option_len=-1
option_len+=1
random.shuffle(option_list)
screen_manager.current="quiz"
if __name__=='__main__':
LabelBase.register(name="LuckiestGuy", fn_regular='regular.ttf')
MathSolver().run()