Last active
September 14, 2017 14:35
-
-
Save AJNOURI/30ce5d5b7f847bdca2548240aa24ac7e to your computer and use it in GitHub Desktop.
python script for mental math exercices
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import random | |
import subprocess | |
def ab_biggerthan_ten(): | |
# Generate 2 number sum of which <= 10 | |
a = (random.randint(1,9)) | |
rmin = 10-a | |
rmax = 9 | |
b = (random.randint(rmin, rmax)) | |
#print(a,"-",b) | |
return a,b | |
def rounded_ten(): | |
# Generate rounded 10th number | |
ra = (random.randint(20, 99)) | |
modrest = ra % 10 | |
rounded = ra - modrest | |
return rounded | |
def check(answer, result): | |
if answer == result: | |
print("Good!!") | |
else: | |
print("Oops!! Verifiez votre reponse: le resultat est ", result) | |
def func_compl(frank): | |
fnbr=random.randint(frank/10, frank-1) | |
frez = frank - fnbr | |
return fnbr, frank, frez | |
def carryon(): | |
carry = input('<Entrer> pour continuer ...') | |
if carry == '': | |
return True | |
else: | |
return False | |
def compl_question(n1, n2, n3): | |
subprocess.run("clear") | |
print("Trouvez le complementaire de ", n1, "jusqu\'a", n2) | |
answer = '' | |
while not answer.isdigit(): | |
answer = input('==> ') | |
check(int(answer), n3) | |
def comp(): | |
##### menu compl | |
check_exit = True | |
while check_exit: | |
nbr, rank, rez = func_compl(1000) | |
compl_question(nbr, rank, rez) | |
check_exit = carryon() | |
def gen_XX_X(): | |
subprocess.run("clear") | |
x, y = ab_biggerthan_ten() | |
decimal = rounded_ten() | |
a = decimal + x | |
b = y | |
print(a) | |
print("+") | |
print(str(b).rjust(2,' ')) | |
return a, b | |
def gen_XX_XX(): | |
subprocess.run("clear") | |
x, y = ab_biggerthan_ten() | |
decimal1 = rounded_ten() | |
decimal2 = rounded_ten() | |
a = decimal1 + x | |
b = decimal2 + y | |
print(a) | |
print("+") | |
print(str(b).rjust(2,' ')) | |
return a, b | |
def add_XX_X(): | |
check_exit = True | |
while check_exit: | |
a, b = gen_XX_X() | |
ans_add = input("> ") | |
while not ans_add.isdigit(): | |
ans_add = input('> ') | |
check(int(ans_add), a + b) | |
check_exit = carryon() | |
def add_XX_XX(): | |
check_exit = True | |
while check_exit: | |
a, b = gen_XX_XX() | |
ans_add = input("> ") | |
while not ans_add.isdigit(): | |
ans_add = input('> ') | |
check(int(ans_add), a + b) | |
check_exit = carryon() | |
ans = True | |
while ans: | |
subprocess.run("clear") | |
print(""" | |
1.Complementaires | |
Addition | |
2. XX+X | |
3. XX+XX | |
9.Exit/Quit | |
""") | |
ans = input("> ") | |
if ans == "1": | |
comp() | |
elif ans == "2": | |
add_XX_X() | |
elif ans == "3": | |
add_XX_XX() | |
elif ans == "9": | |
exit() | |
else: | |
pass |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment