Skip to content

Commit 7716183

Browse files
committed
new game, brain-gcd
1 parent 02f9aaa commit 7716183

File tree

7 files changed

+57
-0
lines changed

7 files changed

+57
-0
lines changed

Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ brain-even:
1010
brain-calc:
1111
poetry run brain-calc
1212

13+
brain-gcd:
14+
poetry run brain-gcd
15+
1316
build:
1417
poetry build
1518

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,7 @@
66

77
[![asciinema](https://asciinema.org/a/HvyBwauBSvLjuilTqCRT2Gbhn.svg)](https://asciinema.org/a/HvyBwauBSvLjuilTqCRT2Gbhn)
88

9+
[![asciinema](https://asciinema.org/a/PNmEbU9vVlbWT5rvvzptOk1kX.svg)](https://asciinema.org/a/PNmEbU9vVlbWT5rvvzptOk1kX)
10+
911
<a href="https://codeclimate.com/github/Nurzhan2023/python-project-49/maintainability"><img src="https://api.codeclimate.com/v1/badges/364adb79c130f5d257e8/maintainability" /></a>
1012

1.1 KB
Binary file not shown.

brain_games/scripts/brain_gcd.py

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# brain_games/scripts/brain_gcd.py
2+
3+
import random
4+
import prompt
5+
import math
6+
7+
def main():
8+
ROUNDS_COUNT = 3
9+
10+
print("Welcome to the Brain Games!")
11+
name = prompt.string('May I have your name?')
12+
print(f"Hello, {name}!")
13+
print ("Find the greatest common divisor of given numbers.")
14+
15+
for i in range(ROUNDS_COUNT):
16+
17+
number1, number2 = find_divisor()
18+
correct_answer = math.gcd(number1, number2)
19+
20+
print(f"Question: {number1} {number2}")
21+
user_answer = input("Your answer: ")
22+
23+
if user_answer.isdigit() and int(user_answer) == correct_answer:
24+
print("Correct!")
25+
26+
else:
27+
print(f"'{user_answer}' is wrong answer ;(.Correct answer was '{correct_answer}'. ")
28+
print(f"Let's try again, {name}!")
29+
return
30+
print(f"Congratulations, {name}!")
31+
32+
33+
34+
35+
36+
def find_divisor():
37+
number1 = random.randint(1, 100)
38+
number2 = random.randint(1, 100)
39+
return number1, number2
40+
41+
42+
43+
44+
45+
46+
47+
48+
49+
50+
if __name__ == "__main__":
51+
main()
2.14 KB
Binary file not shown.

dist/hexlet_code-0.1.0.tar.gz

2.55 KB
Binary file not shown.

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
[tool.poetry.group.dev.dependencies]
2021
flake8 = "^7.1.1"
2122

0 commit comments

Comments
 (0)