Skip to content

Commit 192e296

Browse files
committed
Добавлена игра brain-calc
1 parent 3472ee1 commit 192e296

File tree

3 files changed

+35
-2
lines changed

3 files changed

+35
-2
lines changed

Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,8 @@ brain-games:
1313
brain-even:
1414
uv run brain-even
1515

16+
brain-calc:
17+
uv run brain-calc
18+
1619
lint:
1720
uv run ruff check brain_games

brain_games/scripts/brain_calc.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#!/usr/bin/env python3
2+
import prompt
3+
import random
4+
def main():
5+
print('Welcome to the Brain Games!')
6+
name = prompt.string('May I have your name? ')
7+
print(f'Hello, {name}')
8+
print('What is the result of the expression?')
9+
n = 0
10+
while n < 3:
11+
num1 = random.randint(1, 50)
12+
num2 = random.randint(1, 50)
13+
operation = random.choice(['+', '-', '*'])
14+
expression = f'{num1} {operation} {num2}'
15+
result = eval(expression)
16+
print(f'Question: {expression}')
17+
answer = int(prompt.string('Your answer: '))
18+
if result == answer:
19+
n += 1
20+
if n<3:
21+
print('Correct!')
22+
else:
23+
print(f'Congratulations, {name}!')
24+
else:
25+
print(f"{answer} is wrong answer ;(. Correct answer was {result}.\nLet's try again, {name}")
26+
break
27+
28+
if __name__ == '__main__':
29+
main()

pyproject.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "hexlet-code"
3-
version = "0.3.0"
3+
version = "0.3.1"
44
description = "Add your description here"
55
readme = "README.md"
66
requires-python = ">=3.10"
@@ -22,4 +22,5 @@ dev = [
2222

2323
[project.scripts]
2424
brain-games = "brain_games.scripts.brain_games:main"
25-
brain-even = "brain_games.scripts.brain_even:main"
25+
brain-even = "brain_games.scripts.brain_even:main"
26+
brain-calc = "brain_games.scripts.brain_calc:main"

0 commit comments

Comments
 (0)