Skip to content

Commit

Permalink
Add game: brain-progression
Browse files Browse the repository at this point in the history
  • Loading branch information
Dmitry-Perexozhev committed Nov 24, 2023
1 parent 4d01d0f commit 83595e9
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 0 deletions.
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,6 @@ brain-calc:

brain-gcd:
poetry run brain-gcd

brain-progression:
poetry run brain-progression
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,5 @@ asciinema game brain-even (https://asciinema.org/a/ai5jn7A3lrUcdwqXUyDEqt4O9)
asciinema game brain-calc (https://asciinema.org/a/5zjMH4tBlli6rwRq09TIg6QSe)

asciinema game brain-gcd (https://asciinema.org/a/JrAlVYJD3mrWSkFc0ZK8FjZ4k)

asciinema game brain-progression (https://asciinema.org/a/eZD5xzdn7lVDwY798sVaUWOyg)
Binary file not shown.
57 changes: 57 additions & 0 deletions brain_games/scripts/brain_progression.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#!/usr/bin/env python3
import prompt
from random import randint, choice


def welcome_user():
global name
name = prompt.string('May I have your name? ')
print(f'Hello, {name}!')


def greeting():
print('Welcome to the Brain Games!')


def try_again(name):
print(f"Let's try again, {name}!")


def congratulations(name):
print(f"Congratulations, {name}!")


def brain_progression():
print('What number is missing in the progression?')
count_correct_answers = 0
while count_correct_answers < 3:
random_start_number = randint(1, 20)
random_step = randint(1, 10)
random_sequence = []
for i in range(10):
random_sequence.append(random_start_number + random_step * i)
random_index_of_seq = randint(0, 9)
correct_answer = str(random_sequence[random_index_of_seq])
random_sequence[random_index_of_seq] = '..'
print('Question:', *random_sequence)
user_answer = prompt.string('Your answer: ')
if user_answer == correct_answer:
print('Correct!')
count_correct_answers += 1
else:
print(f"'{user_answer}' is wrong answer ;(."
f" Correct answer was '{correct_answer}'.")
try_again(name)
break
if count_correct_answers == 3:
congratulations(name)


def main():
greeting()
welcome_user()
brain_progression()


if __name__ == '__main__':
main()
Binary file modified dist/hexlet_code-0.1.0-py3-none-any.whl
Binary file not shown.
Binary file modified dist/hexlet_code-0.1.0.tar.gz
Binary file not shown.
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ brain-games = "brain_games.scripts.brain_games:main"
brain-even = "brain_games.scripts.brain_even:main"
brain-calc = "brain_games.scripts.brain_calc:main"
brain-gcd = "brain_games.scripts.brain_gcd:main"
brain-progression = "brain_games.scripts.brain_progression:main"

[tool.poetry.group.dev.dependencies]
flake8 = "^6.1.0"
Expand Down

0 comments on commit 83595e9

Please sign in to comment.