Skip to content

Commit df01847

Browse files
committed
add: brain_progression.py and progression.py
1 parent 0f9826c commit df01847

File tree

5 files changed

+46
-1
lines changed

5 files changed

+46
-1
lines changed

Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,10 @@ lint:
1919
uv run ruff check brain_games/scripts/brain_even.py
2020
uv run ruff check brain_games/scripts/brain_calc.py
2121
uv run ruff check brain_games/scripts/brain_gcd.py
22+
uv run ruff check brain_games/scripts/brain_progression.py
2223
uv run ruff check brain_games/games/even.py
2324
uv run ruff check brain_games/games/calc.py
2425
uv run ruff check brain_games/games/gcd.py
26+
uv run ruff check brain_games/games/progression.py
2527
uv run ruff check brain_games/utils.py
2628
uv run ruff check brain_games/engine.py

brain_games/games/gcd.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,4 @@ def get_right_answer(expression: str) -> str:
2727

2828

2929
def get_msg_game_rules() -> str:
30-
return "Find the greatest common divisor of given numbers."
30+
return "Find the greatest common divisor of given numbers."

brain_games/games/progression.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import random
2+
3+
from brain_games.utils import ask_answer
4+
5+
hidden_number: str
6+
7+
8+
def get_answer_and_right_answer(expression: str) -> tuple:
9+
answer = ask_answer()
10+
right_answer = get_right_answer(expression)
11+
return (answer, right_answer)
12+
13+
14+
def get_question_msg() -> str:
15+
length = random.randint(5, 10)
16+
position = random.randint(0, length - 1)
17+
start_num = random.randint(0, 10)
18+
step = random.randint(1, 10)
19+
stop_num = start_num + step * (length - 1)
20+
progression_lst = [str(num) for num in range(start_num, stop_num, step)]
21+
global hidden_number
22+
hidden_number = progression_lst[position]
23+
progression_lst[position] = '..'
24+
return ' '.join(progression_lst)
25+
26+
27+
def get_right_answer(expression: str) -> str:
28+
return hidden_number
29+
30+
31+
def get_msg_game_rules() -> str:
32+
return "What number is missing in the progression?"
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
from brain_games import engine
2+
from brain_games.games import progression
3+
4+
5+
def main() -> None:
6+
engine.engine_run(progression)
7+
8+
9+
if __name__ == '__main__':
10+
main()

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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)