Skip to content

Commit 48b4edd

Browse files
committed
Add brain-gcd
1 parent c095d55 commit 48b4edd

File tree

3 files changed

+37
-1
lines changed

3 files changed

+37
-1
lines changed

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,7 @@
99
[![asciicast](https://asciinema.org/a/qZlswideTs2fVDc6qpCy2EsIc.svg)](https://asciinema.org/a/qZlswideTs2fVDc6qpCy2EsIc)
1010

1111
### Brain-Calc Test:
12-
[![asciicast](https://asciinema.org/a/mkMowswaIrjQpgW8QyvtBGrHi.svg)](https://asciinema.org/a/mkMowswaIrjQpgW8QyvtBGrHi)
12+
[![asciicast](https://asciinema.org/a/mkMowswaIrjQpgW8QyvtBGrHi.svg)](https://asciinema.org/a/mkMowswaIrjQpgW8QyvtBGrHi)
13+
14+
### Brain-Gcd Test:
15+
[![asciicast](https://asciinema.org/a/Sx9fBpsgZRe3CRAhZfg5HmU8Y.svg)](https://asciinema.org/a/Sx9fBpsgZRe3CRAhZfg5HmU8Y)

brain_games/scripts/brain_gcd.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
from random import randint
2+
from sys import exit
3+
from prompt import string
4+
from math import gcd
5+
6+
QUESTION = 'Find the greatest common divisor of given numbers.'
7+
8+
9+
def get_numbers():
10+
num1, num2 = randint(1, 50), randint(1, 50)
11+
return num1, num2
12+
13+
14+
def main():
15+
print('Welcome to the Brain Games!')
16+
name = string('May I have your name? ')
17+
print(f'Hello, {name}!')
18+
print(QUESTION)
19+
counter = 0
20+
while counter < 3:
21+
num1, num2 = get_numbers()
22+
print(f'Question: {num1} {num2}')
23+
user_answer = string('Your answer: ')
24+
if user_answer == str(gcd(num1, num2)):
25+
print('Correct!')
26+
else:
27+
print(f"'{user_answer}' is wrong answer ;(. Correct answer was '{gcd(num1, num2)}'.")
28+
print(f"Let's try again, {name}!")
29+
exit(0)
30+
counter += 1
31+
print(f'Congratulations, {name}!')
32+
exit(0)

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ prompt = "^0.4.1"
1616
brain-games = "brain_games.scripts.brain_games:main"
1717
brain-even = "brain_games.scripts.brain_even:main"
1818
brain-calc = "brain_games.scripts.brain_calc:main"
19+
brain-gcd = "brain_games.scripts.brain_gcd:main"
1920

2021
[tool.poetry.group.dev.dependencies]
2122
flake8 = "^7.1.1"

0 commit comments

Comments
 (0)