Skip to content

Commit 4d51494

Browse files
committed
new game brain-progression
1 parent 7716183 commit 4d51494

File tree

5 files changed

+64
-0
lines changed

5 files changed

+64
-0
lines changed

Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ brain-calc:
1313
brain-gcd:
1414
poetry run brain-gcd
1515

16+
17+
brain-progression:
18+
poetry run brain-progression
19+
1620
build:
1721
poetry build
1822

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,7 @@
88

99
[![asciinema](https://asciinema.org/a/PNmEbU9vVlbWT5rvvzptOk1kX.svg)](https://asciinema.org/a/PNmEbU9vVlbWT5rvvzptOk1kX)
1010

11+
[![asciinema](https://asciinema.org/a/PSMfRjtLIYa1SfJU35MwgvQqp.svg)](https://asciinema.org/a/PSMfRjtLIYa1SfJU35MwgvQqp)
12+
1113
<a href="https://codeclimate.com/github/Nurzhan2023/python-project-49/maintainability"><img src="https://api.codeclimate.com/v1/badges/364adb79c130f5d257e8/maintainability" /></a>
1214

1.37 KB
Binary file not shown.
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# brain_games/scripts/brain_progression.py
2+
3+
import random
4+
import prompt
5+
6+
def main():
7+
ROUNDS_COUNT = 3
8+
9+
print("Welcome to the Brain Games!")
10+
name = prompt.string("May I have your name?")
11+
print(f"Hello, {name}!")
12+
print("What number is missing in the progression?")
13+
14+
15+
for a in range(ROUNDS_COUNT):
16+
progression, correct_answer = generate_progression()
17+
print(f"Question: {' '.join(map(str, progression))}")
18+
user_answer = input("Your answer: ")
19+
20+
if user_answer.isdigit() and int(user_answer) == correct_answer:
21+
print("Correct!")
22+
23+
else:
24+
print(f"'{user_answer}' is wrong answer ;(. Correct answer was '{correct_answer}'.")
25+
print(f"Let's try again, {name}!")
26+
return
27+
28+
print(f"Congratulations, {name}!")
29+
30+
31+
32+
33+
34+
35+
def generate_progression():
36+
37+
start = random.randint(1, 10)
38+
step = random.randint(2, 10)
39+
length = random.randint(5, 10)
40+
progression = [start + i * step for i in range(length)]
41+
hidden_index = random.randint(0, length -1)
42+
hidden_value = progression[hidden_index]
43+
progression[hidden_index] = ".."
44+
return progression, hidden_value
45+
46+
47+
48+
49+
50+
51+
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
@@ -17,6 +17,7 @@ brain-games = "brain_games.scripts.brain_games:main"
1717
brain-even = "brain_games.scripts.brain_even:main"
1818
brain-calc = "brain_games.scripts.brain_calc:main"
1919
brain-gcd = "brain_games.scripts.brain_gcd:main"
20+
brain-progression = "brain_games.scripts.brain_progression:main"
2021
[tool.poetry.group.dev.dependencies]
2122
flake8 = "^7.1.1"
2223

0 commit comments

Comments
 (0)