-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMath Tester.py
63 lines (61 loc) · 1.86 KB
/
Math Tester.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
#-*-coding:utf8;-*-
# qpy:2
# qpy:console
# My very first program on python for my daughter first math problems.
# Need qpython3 application for android (python3 mac or windows)
# Lets play
from random import randint
import android
import sys
import random
import time
correct = 0
rng = 3
starnum = 5
speak = True
print("Hello Melissa")
droid=android.Android()
def ttsslow(millis):
time.sleep(millis)
droid.ttsSpeak("bonjour melissa")
ttsslow(2)
droid.ttsSpeak("est-ce que tu est pret?")
ttsslow(2)
while True:
for i in range (rng): # (number of questions)
n1 = randint(0,starnum) # (numbers to choose randomly)
n2 = randint(0,n1)
opera = random.choice(r'+-') # random operation choosing could be '+-*/' depend on complexity
resultat = eval(str(n1) + opera + str(n2))
print(n1,opera,n2,end="")
if opera == "-": opera = "moins"
if speak:
ttsslow(1.5)
droid.ttsSpeak(str(n1))
ttsslow(0.5)
droid.ttsSpeak(str(opera))
ttsslow(0.5)
droid.ttsSpeak(str(n2))
inp=(input(" = "))
if inp.isdigit(): # check if valid integer not empty
ans = int(inp)
else:
ans = 0
if ans == resultat:
#print("TRUE. :) \n\n")
droid.ttsSpeak("ces vrai")
correct = correct + 1
else:
#print("FALSE :( , Answer is %d.\n\n" % resultat)
droid.ttsSpeak("ces faux. le resultat est %s" % (resultat))
print("\nResults %d / %d." % (rng,correct))
ttsslow(1.5)
droid.ttsSpeak("tu a reussi %s questions sur %s" % (str(correct), str(rng)))
yes = set(['yes','y', 'ye', ''])
no = set(['no','n'])
droid.ttsSpeak("est-ce que on essay Encore en fois ?")
choice = input("Start again? ").lower()
if choice in no:
break
else:
correct = 0