Skip to content

Commit

Permalink
Add game: brain-gcd
Browse files Browse the repository at this point in the history
  • Loading branch information
Dmitry-Perexozhev committed Nov 23, 2023
1 parent 1bf858f commit 4d01d0f
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 1 deletion.
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,7 @@ brain-even:
poetry run brain-even

brain-calc:
poetry run brain-calc
poetry run brain-calc

brain-gcd:
poetry run brain-gcd
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,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)
54 changes: 54 additions & 0 deletions brain_games/scripts/brain_gcd.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
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_gcd():
print('Find the greatest common divisor of given numbers.')
count_correct_answers = 0
while count_correct_answers < 3:
first_random_number = randint(1, 100)
second_random_number = randint(1, 100)
correct_answer = 1
for i in range(2, min(first_random_number, second_random_number)+1):
if first_random_number % i == 0 and second_random_number % i == 0:
correct_answer = i
print(f'Question: {first_random_number} {second_random_number}')
user_answer = prompt.string('Your answer: ')
if user_answer == str(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_gcd()


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 @@ -16,6 +16,7 @@ prompt = "^0.4.1"
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"

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

0 comments on commit 4d01d0f

Please sign in to comment.