Skip to content

Commit d951e34

Browse files
author
Виталий
committed
Merge branch 'main' into HEAD
2 parents ee6c6d1 + c13bc8d commit d951e34

File tree

7 files changed

+96
-0
lines changed

7 files changed

+96
-0
lines changed

Makefile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,9 @@ package-install:
1111
uv tool install dist/*.whl
1212

1313
reinstall-package:
14+
uv build
1415
uv tool install --upgrade dist/*.whl
16+
17+
lint:
18+
uv run ruff check brain_games
19+

brain_games/cli.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import prompt
22

3+
34
def welcome_user() -> str:
45
print('Welcome to the Brain Games!')
56
name = prompt.string('May I have your name? ')

brain_games/scripts/brain_even.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
from random import randint
2+
3+
import prompt
4+
5+
import brain_games.cli
6+
7+
8+
def game_even():
9+
name = brain_games.cli.welcome_user()
10+
print('Answer "yes" if the number is even, otherwise answer "no".')
11+
num_questions = 3
12+
num_errors = 0
13+
while num_questions > 0:
14+
number = randint(1, 100)
15+
if number % 2 == 0:
16+
right_answer = 'yes'
17+
else:
18+
right_answer = 'no'
19+
print(f'Question: {number}')
20+
response_user = prompt.string('Your answer: ')
21+
if response_user == right_answer:
22+
print('Correct!')
23+
num_questions -= 1
24+
else:
25+
print(f"'{response_user}' is wrong answer ;(. ", end='')
26+
print(f"Correct answer was '{right_answer}'.")
27+
print(f"Let's try again, {name}!")
28+
num_questions = 0
29+
num_errors = 1
30+
if num_errors == 0:
31+
print(f"Congratulations, {name}!")
32+
33+
34+
def main():
35+
game_even()
36+
37+
38+
if __name__ == '__main__':
39+
main()

brain_games/scripts/brain_games.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
import brain_games.cli
22

3+
34
def greeting():
45
print('Welcome to the Brain Games!')
6+
57

68
def main():
79
brain_games.cli.welcome_user()
810

11+
912
if __name__ == '__main__':
1013
main()

pyproject.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,11 @@ build-backend = "hatchling.build"
1515
[tool.hatch.build.targets.wheel]
1616
packages = ["brain_games"]
1717

18+
[dependency-groups]
19+
dev = [
20+
"ruff>=0.8.4",
21+
]
22+
1823
[project.scripts]
1924
brain-games = 'brain_games.scripts.brain_games:main'
25+
brain-even = 'brain_games.scripts.brain_even:main'

ruff.toml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
line-length = 80
2+
3+
[lint.per-file-ignores]
4+
# init modules can contain the local imports, logic, unused imports
5+
"__init__.py" = ["F401"]
6+
7+
[lint]
8+
preview = true
9+
select = ["E", "F", "I", "C90"]

uv.lock

Lines changed: 33 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)