-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
ilya.astakhov
committed
Oct 21, 2024
1 parent
f94b033
commit bf5c613
Showing
1 changed file
with
16 additions
and
70 deletions.
There are no files selected for viewing
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
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"]) |