Skip to content

Instantly share code, notes, and snippets.

@chicagomg
Last active March 30, 2022 07:01
Show Gist options
  • Save chicagomg/4893ee74abfe5ee3dfbf556632341569 to your computer and use it in GitHub Desktop.
Save chicagomg/4893ee74abfe5ee3dfbf556632341569 to your computer and use it in GitHub Desktop.
Математика для ребенка
#!/usr/bin/env python3
import random
import os
from num2words import num2words
n = 0
points = 25 # количество попыток
language = "en" # язык приложения
RED='\033[1;31m'
GRN='\033[1;32m'
YEL='\033[1;33m'
BLU='\033[1;34m'
NC='\033[0m' # No Color
def main():
global n
if language == "en":
plus = "plus"
minus = "minus"
equal = "equal"
done = "solved"
elif language == "pt":
plus = "mais"
minus = "menos"
equal = "é igual a"
done = "decidiu"
elif language == "ru":
plus = "плюс"
minus = "минус"
equal = "равно"
done = "РЕШЕНО"
a = random.randint(1,10)
b = random.randint(5,9)
action_plus = a+b
action_minus = a-b
action = [action_plus, action_minus]
if a > b:
c = random.choice(action)
else:
c = action_plus #random.choice(action)
if c == action_plus:
print("zero one two three four five six seven eight nine")
print("ten eleven twelve thirteen fourteen fifteen sixteen seventeen eighteen nineteen")
print(YEL, num2words(a, lang=language), plus, num2words(b, lang=language), equal, NC)
#print(a, "+", b, "=")
elif c == action_minus:
print("zero one two three four five six seven eight nine")
print("ten eleven twelve thirteen fourteen fifteen sixteen seventeen eighteen nineteen")
print(YEL, num2words(a, lang=language), minus, num2words(b, lang=language), equal, NC)
#print(a, "-", b, "=")
value = input()
if n == points-1:
os.system('cls||clear')
print(done)
exit(1)
else:
if value == num2words(c):
n += 1
os.system('cls||clear')
itog=num2words(n,lang=language)
print(GRN, itog, NC)
print("")
return(n)
else:
n -= 2
os.system('cls||clear')
itog=num2words(n,lang=language)
print(RED, itog, NC)
print("")
return(n)
os.system('cls||clear')
while n < points:
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment