Skip to content

Commit fca5798

Browse files
committed
Add progression.py, scripts/brain_progression.py, update pyproject.toml
1 parent 3d9b6b3 commit fca5798

File tree

7 files changed

+138
-3
lines changed

7 files changed

+138
-3
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,5 @@ brain-calc asciinema.org
1818
https://asciinema.org/a/mEErFUxBs3tsQ8hsQ4a4kcCCT
1919
brain-gcd asciinema.org
2020
https://asciinema.org/a/NK5xTfNSEInZOxxvc2jcr7XbN
21+
brain-progression asciinema.org
22+
https://asciinema.org/a/n70jSFepIQlKTPKmGhWH7QCed

brain_games/games/progression.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import secrets
2+
3+
4+
def generate_round() -> tuple[str, str]:
5+
# Параметры прогрессии
6+
start = secrets.randbelow(15) + 1 # начальное исло
7+
step = secrets.randbelow(10) + 1 # шаг
8+
length = secrets.randbelow(6) + 5 # длина
9+
10+
# прогрессия
11+
progression = []
12+
for i in range(length):
13+
progression.append(str(start + i * step))
14+
15+
# случайная позиция скрытого элемента
16+
hidden_index = secrets.randbelow(length)
17+
carrect_answer = progression[hidden_index]
18+
progression[hidden_index] = ".."
19+
20+
guestion = " ".join(progression)
21+
22+
return guestion, carrect_answer

brain_games/scripts/brain_gcd.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22
from brain_games.engine import run_game
33
from brain_games.games.gcd import generate_round
44

5-
DESCRIPTION = 'Find the greatest common divisor of given numbers.'
5+
DESCRIPTION = "Find the greatest common divisor of given numbers."
66

77

88
def main():
99
run_game(DESCRIPTION, generate_round)
1010

1111

12-
if __name__ == '__main__':
12+
if __name__ == "__main__":
1313
main()
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/usr/bin/env python3
2+
from brain_games.engine import run_game
3+
from brain_games.games.progression import generate_round
4+
5+
DESCRIPTION = "What number is missing in the progression?"
6+
7+
8+
def main():
9+
run_game(DESCRIPTION, generate_round)
10+
11+
12+
if __name__ == "__main__":
13+
main()

demo1.cast

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
{"version": 2, "width": 83, "height": 50, "timestamp": 1763717743, "env": {"SHELL": "/bin/bash", "TERM": "xterm"}}
2+
[0.055616, "o", "\u001b[?2004h💻 \u001b[1;34mpython-project-49\u001b[m\u001b[32m (main)\u001b[00m $ "]
3+
[1.092206, "o", "r"]
4+
[2.508672, "o", "\b\u001b[K"]
5+
[3.173293, "o", "b"]
6+
[3.684536, "o", "r"]
7+
[4.364669, "o", "a"]
8+
[4.957674, "o", "i"]
9+
[5.556815, "o", "n"]
10+
[6.508541, "o", "-"]
11+
[7.949328, "o", "g"]
12+
[8.444779, "o", "c"]
13+
[8.749759, "o", "d"]
14+
[9.661132, "o", "\r\n\u001b[?2004l\r"]
15+
[9.698002, "o", "Welcome to the Brain Games!"]
16+
[9.698097, "o", "\r\nMay I have your name? "]
17+
[11.267797, "o", "A"]
18+
[11.900653, "o", "l"]
19+
[12.652643, "o", "\r\n"]
20+
[12.653726, "o", "Hello, Al!\r\nFind the greatest common divisor of given numbers.\r\nQuestion: 36 38\r\nYour answer: "]
21+
[30.683758, "o", "2"]
22+
[31.596131, "o", "\r\nCorrect!\r\nQuestion: 50 5\r\nYour answer: "]
23+
[35.571844, "o", "5"]
24+
[36.404735, "o", "\r\n"]
25+
[36.404941, "o", "Correct!"]
26+
[36.404993, "o", "\r\nQuestion: 44 7\r\nYour answer: "]
27+
[50.707262, "o", "1"]
28+
[51.371855, "o", "\r\nCorrect!\r\nCongratulations, Al!\r\n"]
29+
[51.395949, "o", "\u001b[?2004h💻 \u001b[1;34mpython-project-49\u001b[m\u001b[32m (main)\u001b[00m $ "]
30+
[54.87538, "o", "brain-gcd"]
31+
[55.835827, "o", "\r\n\u001b[?2004l\r"]
32+
[55.877537, "o", "Welcome to the Brain Games!\r\n"]
33+
[55.878304, "o", "May I have your name? "]
34+
[57.546613, "o", "A"]
35+
[58.274645, "o", "l"]
36+
[59.0348, "o", "\r\n"]
37+
[59.035783, "o", "Hello, Al!"]
38+
[59.036825, "o", "\r\nFind the greatest common divisor of given numbers.\r\nQuestion: 40 6\r\nYour answer: "]
39+
[62.035008, "o", "7"]
40+
[62.738951, "o", "\r\n"]
41+
[62.739457, "o", "'7' is wrong answer ;(. Correct answer was '2'."]
42+
[62.739822, "o", "\r\nLet's try again, Al!\r\n"]
43+
[62.76125, "o", "\u001b[?2004h💻 \u001b[1;34mpython-project-49\u001b[m\u001b[32m (main)\u001b[00m $ "]
44+
[65.71593, "o", "\u001b[?2004l\r\r\nexit\r\n"]

demo2.cast

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
{"version": 2, "width": 88, "height": 50, "timestamp": 1763807626, "env": {"SHELL": "/bin/bash", "TERM": "xterm"}}
2+
[0.046778, "o", "\u001b[?2004h💻 \u001b[1;34mpython-project-49\u001b[m\u001b[32m (main)\u001b[00m $ "]
3+
[1.719801, "o", "b"]
4+
[3.429643, "o", "r"]
5+
[3.959476, "o", "a"]
6+
[4.486315, "o", "i"]
7+
[5.119074, "o", "n"]
8+
[5.988743, "o", "-"]
9+
[8.438053, "o", "p"]
10+
[8.75852, "o", "r"]
11+
[9.09252, "o", "o"]
12+
[9.831832, "o", "g"]
13+
[10.407211, "o", "r"]
14+
[11.303987, "o", "e"]
15+
[12.396669, "o", "s"]
16+
[12.657785, "o", "s"]
17+
[13.026172, "o", "i"]
18+
[13.387153, "o", "o"]
19+
[13.838983, "o", "n"]
20+
[14.202731, "o", "\r\n\u001b[?2004l\r"]
21+
[14.234329, "o", "Welcome to the Brain Games!"]
22+
[14.235122, "o", "\r\nMay I have your name? "]
23+
[16.343092, "o", "A"]
24+
[17.087448, "o", "l"]
25+
[18.082146, "o", "\r\n"]
26+
[18.082983, "o", "Hello, Al!\r\nWhat number is missing in the progression?\r\nQuestion: 7 14 21 28 ..\r\nYour answer: "]
27+
[33.370824, "o", "3"]
28+
[33.941539, "o", "5"]
29+
[34.82588, "o", "\r\n"]
30+
[34.826014, "o", "Correct!\r\nQuestion: 12 19 26 33 40 47 54 ..\r\nYour answer: "]
31+
[43.750136, "o", "6"]
32+
[44.307691, "o", "1"]
33+
[45.401806, "o", "\r\n"]
34+
[45.402774, "o", "Correct!\r\nQuestion: 12 13 .. 15 16 17 18 19 20\r\nYour answer: "]
35+
[53.795881, "o", "1"]
36+
[54.45972, "o", "4"]
37+
[55.449375, "o", "\r\n"]
38+
[55.450212, "o", "Correct!\r\nCongratulations, Al!\r\n"]
39+
[55.471117, "o", "\u001b[?2004h💻 \u001b[1;34mpython-project-49\u001b[m\u001b[32m (main)\u001b[00m $ "]
40+
[57.744916, "o", "brain-progression"]
41+
[59.15441, "o", "\r\n\u001b[?2004l\r"]
42+
[59.185118, "o", "Welcome to the Brain Games!"]
43+
[59.185262, "o", "\r\nMay I have your name? "]
44+
[61.014465, "o", "A"]
45+
[61.717559, "o", "l"]
46+
[62.681705, "o", "\r\n"]
47+
[62.682185, "o", "Hello, Al!\r\nWhat number is missing in the progression?\r\nQuestion: 12 22 32 42 ..\r\nYour answer: "]
48+
[64.608212, "o", "0"]
49+
[65.633948, "o", "\r\n"]
50+
[65.634233, "o", "'0' is wrong answer ;(. Correct answer was '52'.\r\nLet's try again, Al!\r\n"]
51+
[65.656202, "o", "\u001b[?2004h💻 \u001b[1;34mpython-project-49\u001b[m\u001b[32m (main)\u001b[00m $ "]
52+
[69.160179, "o", "\u001b[?2004l\r\r\n"]
53+
[69.162459, "o", "exit\r\n"]

pyproject.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[project]
22
name = "hexlet-code"
33
version = "0.1.0"
4-
description = "Add your description here"
4+
description = "Console games"
55
readme = "README.md"
66
requires-python = ">=3.12"
77
dependencies = [
@@ -25,3 +25,4 @@ brain-games = "brain_games.scripts.brain_games:main"
2525
brain-even = "brain_games.scripts.brain_even:main"
2626
brain-calc = "brain_games.scripts.brain_calc:main"
2727
brain-gcd = "brain_games.scripts.brain_gcd:main"
28+
brain-progression = "brain_games.scripts.brain_progression:main"

0 commit comments

Comments
 (0)