Skip to content

Commit

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

brain-progression:
poetry run brain-progression

brain-prime:
poetry run brain-prime
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,5 @@ 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)

asciinema game brain-prime (https://asciinema.org/a/adu91gryjLGUSof43guMI5htV)
Binary file not shown.
55 changes: 55 additions & 0 deletions brain_games/scripts/brain_prime.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#!/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_prime():
print('Answer "yes" if given number is prime. Otherwise answer "no".')
count_correct_answers = 0
while count_correct_answers < 3:
random_number = randint(3, 100)
correct_answer = 'yes'
for i in range(2, random_number):
if random_number % i == 0:
correct_answer = 'no'
break
print(f'Question: {random_number}')
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_prime()


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 @@ -18,6 +18,7 @@ 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"
brain-prime = "brain_games.scripts.brain_prime:main"

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

0 comments on commit 97c443e

Please sign in to comment.