Skip to content

Commit c355783

Browse files
committed
Add brain-even
1 parent 410619b commit c355783

File tree

9 files changed

+154
-5
lines changed

9 files changed

+154
-5
lines changed

Makefile

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,10 @@ publish:
1111
poetry publish --dry-run
1212

1313
package-install:
14-
python3 -m pip install dist/*.whl
14+
python3 -m pip install dist/*.whl
15+
16+
reinstall:
17+
pip install --force-reinstall dist/*.whl
18+
19+
lint:
20+
poetry run flake8 brain_games

README.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,9 @@
11
### Hexlet tests and linter status:
2-
[![Actions Status](https://github.com/BiscayN/python-project-49/actions/workflows/hexlet-check.yml/badge.svg)](https://github.com/BiscayN/python-project-49/actions)
2+
3+
[![Actions Status](https://github.com/BiscayN/python-project-49/actions/workflows/hexlet-check.yml/badge.svg)](https://github.com/BiscayN/python-project-49/actions)
4+
5+
### CodeClimate status:
6+
[![Maintainability](https://api.codeclimate.com/v1/badges/83457b9fd7b67208524c/maintainability)](https://codeclimate.com/github/BiscayN/python-project-49/maintainability)
7+
8+
### Brain-Even Test:
9+
[![asciicast](https://asciinema.org/a/qZlswideTs2fVDc6qpCy2EsIc.svg)](https://asciinema.org/a/qZlswideTs2fVDc6qpCy2EsIc)

__init__.py

Whitespace-only changes.

brain_games/cli.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
from prompt import string
2+
3+
4+
def welcome_user():
5+
name = string('May I have your name? ')
6+
return (f'Hello, {name}!')

brain_games/scripts/brain_even.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
from random import randint
2+
from sys import exit
3+
from prompt import string
4+
5+
QUESTION = 'Answer "yes" if the number is even, otherwise answer "no".'
6+
7+
8+
def get_number():
9+
return randint(1, 100)
10+
11+
12+
def main():
13+
print('Welcome to the Brain Games!')
14+
name = string('May I have your name? ')
15+
print(f'Hello, {name}!')
16+
print(QUESTION)
17+
counter = 0
18+
while counter < 3:
19+
num = get_number()
20+
print(f'Question: {num}')
21+
user_answer = string('Your answer: ')
22+
if not num % 2:
23+
if user_answer == 'yes':
24+
print('Correct!')
25+
else:
26+
print(f"'{user_answer}' is wrong answer ;(. Correct answer was 'yes'.")
27+
print(f"Let's try again, {name}!")
28+
exit(0)
29+
else:
30+
if user_answer == 'no':
31+
print('Correct!')
32+
else:
33+
print(f"'{user_answer}' is wrong answer ;(. Correct answer was 'no'.")
34+
print(f"Let's try again, {name}!")
35+
exit(0)
36+
counter += 1
37+
print(f'Congratulations, {name}!')
38+
exit(0)

brain_games/scripts/brain_games.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
#!/usr/bin/env python3
22

3+
from brain_games.cli import welcome_user
4+
5+
36
def main():
47
print("Welcome to the Brain Games!")
8+
print(welcome_user())
9+
510

611
if __name__ == '__main__':
7-
main()
12+
main()

poetry.lock

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

pyproject.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,14 @@ packages = [
1010

1111
[tool.poetry.dependencies]
1212
python = "^3.10"
13+
prompt = "^0.4.1"
1314

1415
[tool.poetry.scripts]
1516
brain-games = "brain_games.scripts.brain_games:main"
17+
brain-even = "brain_games.scripts.brain_even:main"
18+
19+
[tool.poetry.group.dev.dependencies]
20+
flake8 = "^7.1.1"
1621

1722
[build-system]
1823
requires = ["poetry-core"]

setup.cfg

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
[flake8]
2+
accept-encodings = utf-8
3+
max-complexity = 6
4+
statistics = False
5+
max-line-length = 80
6+
enable-extensions = G
7+
isort-show-traceback = True
8+
9+
exclude = .git,__pycache__,.venv,dist,build
10+
11+
ignore =
12+
# line break occurred before a binary operator
13+
W503
14+
15+
per-file-ignores =
16+
# init modules can contain the local imports, logic, unused imports
17+
__init__.py: F401
18+
19+
[isort]
20+
multi_line_output = 3
21+
include_trailing_comma = true
22+
default_section = FIRSTPARTY
23+
line_length = 79

0 commit comments

Comments
 (0)