Skip to content

Commit 8e3d61a

Browse files
committed
new game brain-calc
1 parent 5ac337d commit 8e3d61a

File tree

4 files changed

+61
-0
lines changed

4 files changed

+61
-0
lines changed

Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ brain-games:
77
brain-even:
88
poetry run brain-even
99

10+
brain-calc:
11+
poetry run brain-calc
12+
1013
build:
1114
poetry build
1215

1.21 KB
Binary file not shown.

brain_games/scripts/brain_calc.py

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# brain_games/scripts/brain_calc.py
2+
3+
import prompt
4+
import random
5+
6+
def main():
7+
ROUNDS_COUNT = 3
8+
9+
10+
11+
print("Welcome to the Brain Games!")
12+
name = prompt.string('May I have your name?')
13+
print(f"Hello, {name}!")
14+
print("What is the result of the expression?")
15+
16+
17+
for i in range(ROUNDS_COUNT):
18+
question, result = randomaizer()
19+
print(f"Question: {question}")
20+
answer = prompt.string("Your answer: ").strip().lower()
21+
22+
if answer != result:
23+
print(f"'{answer}' is wrong answer ;(. Correct answer was '{result}'.) ")
24+
print(f"Let's try again, {name}!")
25+
return
26+
27+
else:
28+
print("Correct!")
29+
30+
print(f"Congratulations, {name}!")
31+
32+
33+
34+
35+
36+
37+
def randomaizer():
38+
number1 = random.randint(1, 100)
39+
number2 = random.randint(1, 100)
40+
operator = random.choice(['+', '-', '*'])
41+
if operator == '+':
42+
question = (f"{number1}{operator}{number2}")
43+
result = number1 + number2
44+
elif operator == '-':
45+
question = (f"{number1}{operator}{number2}")
46+
result = number1 - number2
47+
elif operator == '*':
48+
question = (f"{number1}{operator}{number2}")
49+
result = number1 * number2
50+
51+
return question, str(result)
52+
53+
54+
55+
56+
if __name__ == "__main__":
57+
main()

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ prompt = "^0.4.1"
1515
[tool.poetry.scripts]
1616
brain-games = "brain_games.scripts.brain_games:main"
1717
brain-even = "brain_games.scripts.brain_even:main"
18+
brain-calc = "brain_games.scripts.brain_calc:main"
1819
[tool.poetry.group.dev.dependencies]
1920
flake8 = "^7.1.1"
2021

0 commit comments

Comments
 (0)