-
Notifications
You must be signed in to change notification settings - Fork 0
/
mmt.py
121 lines (105 loc) · 3.07 KB
/
mmt.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
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
111
112
113
114
115
116
117
118
119
120
121
from random import randint
from random import uniform
from random import choice
# Trainer settings #
print(""" Hi, this is a mental math trainer. It helps you practice your mental arithmatic skills.
You can change the difficulity by changing the range of numbers the program uses to create questions.
The trainer will help you practice on whole and on decimal numbers. The decimal question can be rounded to 2 decimals.
For every correct answer you get 1 point. For every incorrect answer you loose 2 points. Once you reach a score of 100 points the program closes it's self.""")
score = 0
print("Range of numbers for calculations should start at: ")
start = int(input())
print("Range of numbers for calculations should stop at: ")
stop = int(input())
#integer functions
## addition
def additionint():
global score
print("{}+{}".format(a, b))
answer = int(input())
if answer != (a + b):
print("Wrong")
score -= 2
elif answer == (a + b):
score += 1
## substraction
def substractionint():
global score
print("{}-{}".format(a, b))
answer = int(input())
if answer != (a - b):
print("Wrong")
score -= 2
elif answer == (a - b):
score += 1
## multiplication
def multiplicationint():
global score
print("{}*{}".format(a, b))
answer = int(input())
if answer != (a * b):
print("Wrong")
score -= 2
elif answer == (a * b):
score += 1
## division
def divisionint():
global score
print("{}/{}".format(a, b))
answer = float(input())
if answer != round((a / b), 2):
print("Wrong")
score -= 2
elif answer == round((a / b), 2):
score += 1
# float functions
## addition
def additionfloat():
global score
print("{}+{}".format(x, y))
answer = float(input())
if answer != (x + y):
print("Wrong")
score -= 2
elif answer == (x + y):
score += 1
## substraction
def substractionfloat():
global score
print("{}-{}".format(x, y))
answer = float(input())
if answer != (x - y):
print("Wrong")
score -= 2
elif answer == (x - y):
score += 1
## multiplication
def multiplicationfloat():
global score
print("{}*{}".format(x, y))
answer = int(input())
if answer != round((x * y), 2):
print("Wrong")
score -= 2
elif answer == round((x * y), 2):
score += 1
## division
def divisionfloat():
global score
print("{}/{}".format(x, y))
answer = float(input())
if answer != round((x / y), 2):
print("Wrong")
score -= 2
elif answer == round((x / y), 2):
score += 1
# functionlist
functionlist = [additionint, substractionint, multiplicationint, divisionint, additionfloat, substractionfloat, multiplicationfloat, divisionfloat]
# change the number here if you want more or less practice until the program closes
while score < 100:
x = round(uniform(start, stop), 2)
y = round(uniform(start, stop), 2)
a = int(x)
b = int(y)
choice(functionlist)()
print("Good job!")