Skip to content

Commit 2cd4290

Browse files
committed
add brain-gcd
1 parent 2644c1e commit 2cd4290

File tree

3 files changed

+29
-1
lines changed

3 files changed

+29
-1
lines changed

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
### my project brain-games
55
[![Maintainability](https://api.codeclimate.com/v1/badges/<badge-id>/maintainability)](https://codeclimate.com/github/<user>/<repo>/maintainability)
66

7-
### recording game
7+
### recording game even
88
[![asciicast](https://asciinema.org/a/590UtX6yhMaPAhLDUg7RlBWiB.svg)](https://asciinema.org/a/590UtX6yhMaPAhLDUg7RlBWiB)
99

10+
### recording game gcd
11+
[![asciicast](https://asciinema.org/a/gOo07GHNNHydhoDA2jznP24Bn.svg)](https://asciinema.org/a/gOo07GHNNHydhoDA2jznP24Bn)

brain_games/scripts/brain_gcd.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import random
2+
from math import gcd
3+
from brain_games.cli import welcome_user
4+
5+
def main():
6+
user_name = welcome_user()
7+
print("Find the greatest common divisor of given numbers.")
8+
9+
rounds_to_win = 3
10+
for _ in range(rounds_to_win):
11+
number1 = random.randint(1, 100)
12+
number2 = random.randint(1, 100)
13+
print(f"Question: {number1} {number2}")
14+
15+
correct_answer = gcd(number1, number2)
16+
user_answer = input("Your answer: ").strip()
17+
18+
if not user_answer.isdigit() or int(user_answer) != correct_answer:
19+
print(f"'{user_answer}' is wrong answer ;(. Correct answer was '{correct_answer}'.")
20+
print(f"Let's try again, {user_name}!")
21+
return
22+
23+
print("Correct!")
24+
25+
print(f"Congratulations, {user_name}!")

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,4 @@ select = ["E", "F", "I", "C90"]
3434
[project.scripts]
3535
brain-games = "brain_games.scripts.brain_games:main"
3636
brain-even = "brain_games.scripts.brain_even:main"
37+
brain-gcd = "brain_games.scripts.brain_gcd:main"

0 commit comments

Comments
 (0)