Skip to content

Commit 83a4c46

Browse files
committed
add even.py, engine.py, brain_even.py, init__.py, upate pyproject.toml, Makefile, README.md, demo.cast
1 parent 0482f5c commit 83a4c46

File tree

8 files changed

+141
-0
lines changed

8 files changed

+141
-0
lines changed

Makefile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@ build:
1515
package-install:
1616
uv tool install dist/*.whl
1717

18+
package-reinstall:
19+
uv tool install --force dist/*.whl
20+
1821
# Run the linter
1922
lint:
2023
uv run ruff check brain_games
24+
25+
format:
26+
uv run ruff format brain_games

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,7 @@
1010
[![Technical Debt](https://sonarcloud.io/api/project_badges/measure?project=lytic11-web_python-project-49&metric=sqale_index)](https://sonarcloud.io/summary/new_code?id=lytic11-web_python-project-49)
1111
[![Maintainability Rating](https://sonarcloud.io/api/project_badges/measure?project=lytic11-web_python-project-49&metric=sqale_rating)](https://sonarcloud.io/summary/new_code?id=lytic11-web_python-project-49)
1212
[![Vulnerabilities](https://sonarcloud.io/api/project_badges/measure?project=lytic11-web_python-project-49&metric=vulnerabilities)](https://sonarcloud.io/summary/new_code?id=lytic11-web_python-project-49)
13+
14+
15+
brain-even asciinema.org
16+
https://asciinema.org/a/d3XQhtjV2Ir8aSb5XE0Qi1BWm

brain_games/engine.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import prompt
2+
3+
4+
def run_game(game_description: str, generate_round) -> None:
5+
print("Welcome to the Brain Games!")
6+
name = prompt.string('May I have your name? ')
7+
print(f"Hello, {name}!")
8+
9+
print(game_description)
10+
11+
rounds_count = 3
12+
for _ in range(rounds_count):
13+
question, correct_answer = generate_round()
14+
print(f"Question: {question}")
15+
user_answer = prompt.string("Your answer: ")
16+
17+
if user_answer != correct_answer:
18+
print(f"'{user_answer}' is wrong answer ;(. Correct answer was '{correct_answer}'.")
19+
print(f"Let's try again, {name}!")
20+
return
21+
22+
print("Correct!")
23+
24+
print(f"Congratulations, {name}!")

brain_games/games/__init__.py

Whitespace-only changes.

brain_games/games/even.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import random
2+
3+
4+
def is_even(namber: int) -> bool:
5+
return namber % 2 == 0
6+
7+
8+
def generate_round() -> tuple:
9+
number = random.randint(1, 100)
10+
question = str(number)
11+
correct_answer = 'yes' if is_even(number) else 'no'
12+
return question, correct_answer

brain_games/scripts/brain_even.py

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

demo.cast

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
{"version": 2, "width": 80, "height": 50, "timestamp": 1763476190, "env": {"SHELL": "/bin/bash", "TERM": "xterm"}}
2+
[0.054283, "o", "\u001b[?2004h💻 \u001b[1;34mpython-project-49\u001b[m\u001b[32m (main)\u001b[00m $ "]
3+
[3.328276, "o", "\u001b[7mmake build\u001b[27m"]
4+
[4.429754, "o", "\u0007\b\b\b\b\b\b\b\b\b\bmake build"]
5+
[4.829355, "o", "\r\n\u001b[?2004l\r"]
6+
[4.834469, "o", "uv build\r\n"]
7+
[4.851072, "o", "\u001b[1mBuilding source distribution...\u001b[0m\r\n"]
8+
[5.327366, "o", "\u001b[1mBuilding wheel from source distribution...\u001b[0m\r\n"]
9+
[5.66876, "o", "Successfully built \u001b[36m"]
10+
[5.668841, "o", "\u001b[1mdist/hexlet_code-0.1.0.tar.gz\u001b[0m\u001b[39m\r\nSuccessfully built \u001b[36m\u001b[1mdist/hexlet_code-0.1.0-py3-none-any.whl\u001b[0m\u001b[39m\r\n"]
11+
[5.691849, "o", "\u001b[?2004h💻 \u001b[1;34mpython-project-49\u001b[m\u001b[32m (main)\u001b[00m $ "]
12+
[11.75023, "o", "\u001b[7mmake package-reinstall\u001b[27m"]
13+
[12.676972, "o", "\u0007\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\bmake package-reinstall"]
14+
[13.021324, "o", "\r\n\u001b[?2004l\r"]
15+
[13.026635, "o", "uv tool install --force dist/*.whl"]
16+
[13.026784, "o", "\r\n"]
17+
[13.056895, "o", "\u001b[37m⠋\u001b[0m \u001b[2mResolving dependencies... \u001b[0m\r\u001b[2K"]
18+
[13.059649, "o", "\u001b[37m⠋\u001b[0m \u001b[2mResolving dependencies... \u001b[0m"]
19+
[13.061063, "o", "\r\u001b[2K\u001b[37m⠙\u001b[0m \u001b[2mResolving dependencies... \u001b[0m"]
20+
[13.064917, "o", "\r\u001b[2K"]
21+
[13.065061, "o", "\u001b[37m⠋\u001b[0m \u001b[2mResolving dependencies... \u001b[0m"]
22+
[13.066756, "o", "\r\u001b[2K\u001b[37m⠙\u001b[0m \u001b[2mResolving dependencies... \u001b[0m"]
23+
[13.066822, "o", "\r\u001b[2K\u001b[37m⠙\u001b[0m \u001b[2mhexlet-code==0.1.0 \u001b[0m"]
24+
[13.219104, "o", "\r\u001b[2K\u001b[37m⠙\u001b[0m \u001b[2mprompt==0.4.1 \u001b[0m"]
25+
[13.219717, "o", "\r\u001b[2K\u001b[37m⠙\u001b[0m \u001b[2m \u001b[0m\r\u001b[2K"]
26+
[13.220535, "o", "\u001b[2mResolved \u001b[1m2 packages\u001b[0m \u001b[2min 160ms\u001b[0m\u001b[0m\r\n"]
27+
[13.221954, "o", "\u001b[37m⠋\u001b[0m \u001b[2mPreparing packages...\u001b[0m (0/0) "]
28+
[13.222016, "o", "\r\u001b[2K\u001b[37m⠋\u001b[0m \u001b[2mPreparing packages...\u001b[0m (0/1) "]
29+
[13.222936, "o", "\r\u001b[2K\u001b[37m⠙\u001b[0m \u001b[2mPreparing packages...\u001b[0m (0/1) "]
30+
[13.235483, "o", "\r\u001b[2K\u001b[37m⠙\u001b[0m \u001b[2m\u001b[0m (1/1) \r\u001b[2K\u001b[2mPrepared \u001b[1m1 package\u001b[0m \u001b[2min 13ms\u001b[0m\u001b[0m\r\n"]
31+
[13.236614, "o", "\u001b[2mUninstalled \u001b[1m1 package\u001b[0m \u001b[2min 1ms\u001b[0m\u001b[0m\r\n░░░░░░░░░░░░░░░░░░░░ [0/0] \u001b[2mInstalling wheels... \u001b[0m\r\u001b[2K░░░░░░░░░░░░░░░░░░░░ [0/1] \u001b[2mInstalling wheels... \u001b[0m"]
32+
[13.244188, "o", "\r\u001b[2K░░░░░░░░░░░░░░░░░░░░ [0/1] \u001b[2mhexlet-code==0.1.0 (from file:///home/admin1/python-p\u001b[0m\r\u001b[2K████████████████████ [1/1] \u001b[2mhexlet-code==0.1.0 (from file:///home/admin1/python-p\u001b[0m\r\u001b[2K\u001b[2mInstalled \u001b[1m1 package\u001b[0m \u001b[2min 7ms\u001b[0m\u001b[0m\r\n \u001b[33m~\u001b[39m \u001b[1mhexlet-code\u001b[0m\u001b[2m==0"]
33+
[13.245162, "o", ".1.0 (from file:///home/admin1/python-project-49/dist/hexlet_code-0.1.0-py3-none-any.whl)\u001b[0m\r\n"]
34+
[13.245565, "o", "Installed 2 executables: \u001b[1mbrain-even\u001b[0m, \u001b[1mbrain-games\u001b[0m\r\n"]
35+
[13.269208, "o", "\u001b[?2004h💻 \u001b[1;34mpython-project-49\u001b[m\u001b[32m (main)\u001b[00m $ "]
36+
[17.036951, "o", "b"]
37+
[17.597039, "o", "r"]
38+
[18.492959, "o", "a"]
39+
[18.82108, "o", "i"]
40+
[19.373706, "o", "n"]
41+
[20.485067, "o", "-"]
42+
[21.893174, "o", "e"]
43+
[22.396855, "o", "v"]
44+
[22.700929, "o", "e"]
45+
[23.284922, "o", "n"]
46+
[24.325561, "o", "\r\n\u001b[?2004l\r"]
47+
[24.361766, "o", "Welcome to the Brain Games!\r\nMay I have your name? "]
48+
[26.23676, "o", "a"]
49+
[27.260702, "o", "\b \b"]
50+
[27.876848, "o", "A"]
51+
[28.572748, "o", "l"]
52+
[29.292783, "o", "\r\n"]
53+
[29.294869, "o", "Hello, Al!\r\nAnswer \"yes\" if the number is even, otherwise answer \"no\".\r\nQuestion: 97\r\nYour answer: "]
54+
[33.876776, "o", "n"]
55+
[34.508588, "o", "o"]
56+
[35.828947, "o", "\r\nCorrect!\r\nQuestion: 97\r\nYour answer: "]
57+
[38.020257, "o", "n"]
58+
[38.692626, "o", "o"]
59+
[39.884382, "o", "\r\n"]
60+
[39.885014, "o", "Correct!\r\nQuestion: 48\r\nYour answer: "]
61+
[43.900743, "o", "y"]
62+
[44.420673, "o", "e"]
63+
[45.28419, "o", "s"]
64+
[46.252328, "o", "\r\n"]
65+
[46.253158, "o", "Correct!"]
66+
[46.2539, "o", "\r\nCongratulations, Al!\r\n"]
67+
[46.278942, "o", "\u001b[?2004h💻 \u001b[1;34mpython-project-49\u001b[m\u001b[32m (main)\u001b[00m $ "]
68+
[50.020913, "o", "brain-even"]
69+
[51.12587, "o", "\r\n\u001b[?2004l\r"]
70+
[51.15726, "o", "Welcome to the Brain Games!\r\nMay I have your name? "]
71+
[53.980117, "o", "A"]
72+
[54.724221, "o", "l"]
73+
[55.612237, "o", "\r\n"]
74+
[55.613091, "o", "Hello, Al!\r\nAnswer \"yes\" if the number is even, otherwise answer \"no\".\r\nQuestion: 2\r\nYour answer: "]
75+
[59.244145, "o", "n"]
76+
[59.892732, "o", "o"]
77+
[60.700691, "o", "\r\n'no' is wrong answer ;(. Correct answer was 'yes'."]
78+
[60.70087, "o", "\r\nLet's try again, Al!\r\n"]
79+
[60.723274, "o", "\u001b[?2004h💻 \u001b[1;34mpython-project-49\u001b[m\u001b[32m (main)\u001b[00m $ "]
80+
[67.173935, "o", "\u001b[?2004l\r\r\nexit\r\n"]

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,4 @@ dev = [
2222

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

0 commit comments

Comments
 (0)