Skip to content

Commit

Permalink
4.5
Browse files Browse the repository at this point in the history
  • Loading branch information
ilya.astakhov committed Oct 21, 2024
1 parent f94b033 commit bf5c613
Showing 1 changed file with 16 additions and 70 deletions.
86 changes: 16 additions & 70 deletions brain_games/games/calc.py
Original file line number Diff line number Diff line change
@@ -1,77 +1,23 @@
#!/usr/bin/env python3


import random
from brain_games.cli import welcome_user
from brain_games.utils import generate_rand_num
from brain_games.engine import run_game
from brain_games.constants import GAME_INSTRUCTIONS, MATH_SIGNS


def main():
# welcome_user()
calc()
def get_math_expression_and_result():
first_num, second_num = generate_rand_num(10), generate_rand_num(10)
action = random.choice(MATH_SIGNS)

if action == '+':
result = first_num + second_num
elif action == '-':
result = first_num - second_num elif action == '*':
result = first_num * second_num # Если вы добавите деление, убедитесь в обработке деления на ноль


if __name__ == '__main__':
main()
expression = f'{first_num} {action} {second_num}'
return expression, str(result)


def calc():
name1 = welcome_user()
print('What is the result of the expression?')
# первый проход
a = random.randint(1, 9)
b = random.randint(1, 9)
seq = ['+', "-", "*"]
c = random.choice(seq)
print("Question:", a, c, b)
if c == '+':
d = a + b
elif c == '-':
d = a - b
elif c == '*':
d = a * b
y = int(input("Your answer:"))
if y == d:
print('Correct!')
else:
y != d
print("'", y, "' is wrong answer ;(. Correct answer was '", d, "'.\nLet's try again,", name1) # noqa: E501
return
# второй проход
a = random.randint(1, 9)
b = random.randint(1, 9)
seq = ['+', "-", "*"]
c = random.choice(seq)
print("Question:", a, c, b)
if c == '+':
d = a + b
elif c == '-':
d = a - b
elif c == '*':
d = a * b
y = int(input("Your answer:"))
if y == d:
print('Correct!')
else:
y != d
print("'", y, "' is wrong answer ;(. Correct answer was '", d, "'.\nLet's try again,", name1) # noqa: E501
return
# третий проход
a = random.randint(1, 9)
b = random.randint(1, 9)
seq = ['+', "-", "*"]
c = random.choice(seq)
print("Question:", a, c, b)
if c == '+':
d = a + b
elif c == '-':
d = a - b
elif c == '*':
d = a * b
y = int(input("Your answer:"))
if y == d:
print('Correct!\nCongratulations,', name1)
return
else:
y != d
print("'", y, "' is wrong answer ;(. Correct answer was '", d, "'.\nLet's try again,", name1) # noqa: E501
return
def calc_game():
run_game(get_math_expression_and_result, GAME_INSTRUCTIONS["calc"])

0 comments on commit bf5c613

Please sign in to comment.