Skip to content

Commit eda7f23

Browse files
author
shmelevik
committed
add engine (brain_even), add dev dependencies, add demonstration in README, updated packages
1 parent 666e37d commit eda7f23

File tree

12 files changed

+209
-13
lines changed

12 files changed

+209
-13
lines changed

Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,5 @@ build:
1010
package-install:
1111
uv tool install dist/*.whl
1212

13-
13+
lint:
14+
uv run ruff check brain_games

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
11
### Hexlet tests and linter status:
22
[![Actions Status](https://github.com/Shmelevick/python-project-49/actions/workflows/hexlet-check.yml/badge.svg)](https://github.com/Shmelevick/python-project-49/actions)[![Maintainability](https://api.codeclimate.com/v1/badges/48b30ee9e092d6ff1e60/maintainability)](https://codeclimate.com/github/Shmelevick/python-project-49/maintainability)
33
[![Test Coverage](https://api.codeclimate.com/v1/badges/48b30ee9e092d6ff1e60/test_coverage)](https://codeclimate.com/github/Shmelevick/python-project-49/test_coverage)
4+
5+
## 📽️ Example in Action
6+
7+
Check out the demo of the package in action by clicking on the [asciinema recording](https://asciinema.org/a/sOCkYp6t3giKi2DkTCcgzuYUf) below:
8+
9+
![asciinema demo](https://asciinema.org/a/sOCkYp6t3giKi2DkTCcgzuYUf.svg)
8 Bytes
Binary file not shown.

brain_games/cli.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,8 @@
11
import prompt
22

3+
34
def welcome_user():
45
print('Welcome to the Brain Games!')
56
name = prompt.string('May I have your name? ')
6-
print(f'Hello, {name}!')
7-
8-
9-
# def main():
10-
# welcome_user()
11-
12-
13-
# if __name__ == "__main__":
14-
# main()
7+
print(f'Hello, {name}!\n')
8+
return name
1.52 KB
Binary file not shown.
111 Bytes
Binary file not shown.

brain_games/scripts/brain_even.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
from random import randint
2+
from time import sleep
3+
4+
from prompt import string
5+
6+
from brain_games.cli import welcome_user
7+
8+
9+
def is_even_game(name):
10+
sleep(1)
11+
print('Answer "yes" if the number is even, otherwise answer "no".\n')
12+
sleep(2)
13+
14+
correct_guesses = 0
15+
16+
while correct_guesses < 3:
17+
18+
number = randint(1, 10000)
19+
answer = string(f'Question: {number}\nYour answer: ')
20+
correct_answer = 'no' if number % 2 else 'yes'
21+
22+
if answer != correct_answer:
23+
print(
24+
f"'{answer}' is wrong answer ;(. "
25+
f"Correct answer was '{correct_answer}'.\n"
26+
f"Let's try again, {name}!\n\n\n"
27+
)
28+
sleep(2)
29+
30+
correct_guesses = 0
31+
32+
continue
33+
34+
print('Correct!\n')
35+
sleep(1)
36+
37+
correct_guesses += 1
38+
39+
print(f'Congratulations, {name}!\n')
40+
41+
return
42+
43+
44+
def main():
45+
name = welcome_user()
46+
is_even_game(name)
47+
48+
49+
if __name__ == "__main__":
50+
main()

brain_games/scripts/brain_games.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
from brain_games.cli import welcome_user
2+
from brain_games.scripts.brain_even import is_even_game
23

34

45
def main():
5-
welcome_user()
6+
name = welcome_user()
7+
is_even_game(name)
68

79

810
if __name__ == "__main__":
9-
main()
11+
main()

demo.cast

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
{"version": 2, "width": 120, "height": 30, "timestamp": 1741812743, "env": {"SHELL": "/bin/bash", "TERM": "xterm-256color"}}
2+
[0.021325, "o", "\u001b[?2004h\u001b]0;moodeng@DESKTOP: ~/code/hexlet/python_full_course/python-project-49\u0007\u001b[01;32mmoodeng@DESKTOP\u001b[00m:\u001b[01;34m~/code/hexlet/python_full_course/python-project-49\u001b[00m$ "]
3+
[4.816042, "o", "u"]
4+
[4.906952, "o", "v"]
5+
[4.979914, "o", " "]
6+
[5.444858, "o", "s"]
7+
[5.90489, "o", "y"]
8+
[6.571824, "o", "n"]
9+
[6.657981, "o", "c"]
10+
[7.399901, "o", "\r\n"]
11+
[7.400099, "o", "\u001b[?2004l\r"]
12+
[7.420319, "o", "\u001b[2mResolved \u001b[1m9 packages\u001b[0m \u001b[2min 3ms\u001b[0m\u001b[0m\r\n"]
13+
[7.423695, "o", "\u001b[2mAudited \u001b[1m8 packages\u001b[0m \u001b[2min 0.25ms\u001b[0m\u001b[0m\r\n"]
14+
[7.425374, "o", "\u001b[?2004h"]
15+
[7.425491, "o", "\u001b]0;moodeng@DESKTOP: ~/code/hexlet/python_full_course/python-project-49\u0007\u001b[01;32mmoodeng@DESKTOP\u001b[00m:\u001b[01;34m~/code/hexlet/python_full_course/python-project-49\u001b[00m$ "]
16+
[10.503797, "o", "u"]
17+
[10.585848, "o", "v"]
18+
[10.654786, "o", " "]
19+
[11.383757, "o", "r"]
20+
[11.583904, "o", "u"]
21+
[11.803857, "o", "n"]
22+
[11.961997, "o", " "]
23+
[13.785657, "o", "b"]
24+
[14.10878, "o", "r"]
25+
[14.204917, "o", "a"]
26+
[14.377667, "o", "i"]
27+
[14.573653, "o", "n"]
28+
[14.924708, "o", "-"]
29+
[15.362703, "o", "g"]
30+
[15.444575, "o", "a"]
31+
[15.954671, "o", "m"]
32+
[16.059594, "o", "e"]
33+
[16.200955, "o", "s"]
34+
[17.125758, "o", "\r\n\u001b[?2004l\r"]
35+
[17.199558, "o", "Welcome to the Brain Games!\r\nMay I have your name? "]
36+
[24.080338, "o", "N"]
37+
[24.34444, "o", "i"]
38+
[24.581492, "o", "c"]
39+
[24.81852, "o", "k"]
40+
[25.123548, "o", "\r\n"]
41+
[25.123765, "o", "Hello, Nick!\r\n\r\n"]
42+
[26.124761, "o", "Answer \"yes\" if the number is even, otherwise answer \"no\".\r\n\r\n"]
43+
[28.124947, "o", "Question: 9234\r\nYour answer: "]
44+
[30.463449, "o", "y"]
45+
[30.618279, "o", "e"]
46+
[30.705334, "o", "s"]
47+
[30.869382, "o", "\r\n"]
48+
[30.869627, "o", "Correct!\r\n\r\n"]
49+
[31.870557, "o", "Question: 506\r\nYour answer: "]
50+
[33.152348, "o", "y"]
51+
[33.225363, "o", "e"]
52+
[33.338196, "o", "s"]
53+
[33.557893, "o", "\r\n"]
54+
[33.558085, "o", "Correct!\r\n\r\n"]
55+
[34.559043, "o", "Question: 8923\r\nYour answer: "]
56+
[35.748285, "o", "n"]
57+
[35.971311, "o", "o"]
58+
[36.231376, "o", "\r\n"]
59+
[36.23162, "o", "Correct!\r\n\r\n"]
60+
[37.232119, "o", "Congratulations, Nick!\r\n\r\n"]
61+
[37.238611, "o", "\u001b[?2004h\u001b]0;moodeng@DESKTOP: ~/code/hexlet/python_full_course/python-project-49\u0007\u001b[01;32mmoodeng@DESKTOP\u001b[00m:\u001b[01;34m~/code/hexlet/python_full_course/python-project-49\u001b[00m$ "]
62+
[38.970093, "o", "uv run brain-games"]
63+
[39.161217, "o", "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\bsync\u001b[K"]
64+
[40.34205, "o", "\b\b\b\brun brain-games"]
65+
[41.112364, "o", "\r\n\u001b[?2004l\r"]
66+
[41.186246, "o", "Welcome to the Brain Games!\r\nMay I have your name? "]
67+
[45.596065, "o", "N"]
68+
[45.874175, "o", "i"]
69+
[46.334176, "o", "c"]
70+
[46.416125, "o", "k"]
71+
[46.621193, "o", "\r\n"]
72+
[46.621382, "o", "Hello, Nick!\r\n\r\n"]
73+
[47.621699, "o", "Answer \"yes\" if the number is even, otherwise answer \"no\".\r\n\r\n"]
74+
[49.622051, "o", "Question: 9242\r\nYour answer: "]
75+
[50.844045, "o", "n"]
76+
[51.044995, "o", "o"]
77+
[51.33209, "o", "\r\n"]
78+
[51.332329, "o", "'no' is wrong answer ;(. Correct answer was 'yes'.\r\nLet's try again, Nick!\r\n\r\n\r\n\r\n"]
79+
[53.333256, "o", "Question: 2323\r\nYour answer: "]
80+
[54.989974, "o", "n"]
81+
[55.230887, "o", "o"]
82+
[55.500088, "o", "\r\n"]
83+
[55.500306, "o", "Correct!\r\n\r\n"]
84+
[56.501033, "o", "Question: 7658\r\nYour answer: "]
85+
[59.594033, "o", "n"]
86+
[59.721939, "o", "o"]
87+
[60.815014, "o", "\r\n"]
88+
[60.815241, "o", "'no' is wrong answer ;(. Correct answer was 'yes'.\r\nLet's try again, Nick!\r\n\r\n\r\n\r\n"]
89+
[62.815533, "o", "Question: 5678\r\nYour answer: "]
90+
[66.038933, "o", "y"]
91+
[66.18348, "o", "e"]
92+
[66.275778, "o", "s"]
93+
[66.416854, "o", "\r\n"]
94+
[66.417101, "o", "Correct!\r\n\r\n"]
95+
[67.417176, "o", "Question: 8847\r\nYour answer: "]
96+
[70.257821, "o", "n"]
97+
[70.553693, "o", "o"]
98+
[70.986865, "o", "\r\n"]
99+
[70.987066, "o", "Correct!\r\n\r\n"]
100+
[71.987141, "o", "Question: 9008\r\nYour answer: "]
101+
[72.958634, "o", "y"]
102+
[73.04112, "o", "e"]
103+
[73.141656, "o", "s"]
104+
[73.373944, "o", "\r\n"]
105+
[73.374135, "o", "Correct!\r\n\r\n"]
106+
[74.37488, "o", "Congratulations, Nick!\r\n\r\n"]
107+
[74.381084, "o", "\u001b[?2004h\u001b]0;moodeng@DESKTOP: ~/code/hexlet/python_full_course/python-project-49\u0007\u001b[01;32mmoodeng@DESKTOP\u001b[00m:\u001b[01;34m~/code/hexlet/python_full_course/python-project-49\u001b[00m$ "]
108+
[78.3257, "o", "\u001b[?2004l\r\r\n"]
109+
[78.325893, "o", "exit\r\n"]

pyproject.toml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ requires-python = ">=3.13"
77
dependencies = [
88
"prompt>=0.4.1",
99
"pytest>=8.3.5",
10-
"ruff>=0.9.10",
1110
]
1211

1312
[build-system]
@@ -17,5 +16,12 @@ build-backend = "hatchling.build"
1716
[tool.hatch.build.targets.wheel]
1817
packages = ["brain_games"]
1918

19+
[dependency-groups]
20+
dev = [
21+
"asciinema",
22+
"ruff>=0.9.10",
23+
]
24+
2025
[project.scripts]
2126
brain-games = "brain_games.scripts.brain_games:main"
27+
brain-even = "brain_games.scripts.brain_even:main"

0 commit comments

Comments
 (0)