Skip to content

Commit 9262b5b

Browse files
committed
all changes 7-th step of project
1 parent 56297e1 commit 9262b5b

File tree

9 files changed

+40
-11
lines changed

9 files changed

+40
-11
lines changed

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33

44
<a href="https://codeclimate.com/github/ttehasi/python-project-49/maintainability"><img src="https://api.codeclimate.com/v1/badges/0196f25b462ce6f82ac1/maintainability" /></a>
55

6-
brain_even: https://asciinema.org/a/5JkOomCYitwZ5YMmXGrbKf7vO
6+
brain-even: https://asciinema.org/a/5JkOomCYitwZ5YMmXGrbKf7vO
77

8-
brain_calc: https://asciinema.org/a/daDnWV3XC3pNoNAFgOneXFrU7
8+
brain-calc: https://asciinema.org/a/daDnWV3XC3pNoNAFgOneXFrU7
9+
10+
brain-gdc:
864 Bytes
Binary file not shown.
630 Bytes
Binary file not shown.

brain_games/scripts/games/brain_calc.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
import brain_games.scripts.games.sample
22

33

4-
NUMBERS_OF_ATTEMPTS = 3
5-
6-
74
def calc_game():
85
cond_answer = 'What is the result of the expression?'
96
return brain_games.scripts.games.sample.samples('brain-calc', cond_answer)
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import brain_games.scripts.games.sample
2+
3+
4+
def game_gcd():
5+
cond_answer = 'Find the greatest common divisor of given numbers.'
6+
return brain_games.scripts.games.sample.samples('brain-gcd', cond_answer)
7+
8+
9+
def main():
10+
print('Welcome to the Brain Games!')
11+
print(game_gcd())
12+
13+
14+
if __name__ == '__main__':
15+
main()

brain_games/scripts/games/sample.py

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,22 +23,36 @@ def type_brain_calc(first_number, sec_number):
2323
return correct_answer
2424

2525

26+
def type_brain_gcd(frs_num, sec_num):
27+
re = []
28+
max_num = max(frs_num, sec_num)
29+
for i in range(1, max_num):
30+
if frs_num % i == 0 and sec_num % i == 0:
31+
re.append(i)
32+
print(f'Question: {frs_num} {sec_num}')
33+
return max(re)
34+
35+
2636
def samples(type_game, condition_answer):
2737
name = prompt.string('May I have your name? ')
2838
number_of_successful_attempts = 0
2939
print(condition_answer)
3040
for _ in range(NUMBERS_OF_ATTEMPTS):
31-
first_number = random.randint(0, 25)
32-
second_number = random.randint(0, 25)
41+
first_number = random.randint(1, 50)
42+
second_number = random.randint(1, 50)
3343
if type_game == 'brain-even':
3444
correct_answer = type_brain_even(first_number)
35-
else:
45+
elif type_game == 'brain-calc':
46+
first_number = random.randint(1, 25)
47+
second_number = random.randint(1, 25)
3648
correct_answer = type_brain_calc(first_number, second_number)
49+
else:
50+
correct_answer = type_brain_gcd(first_number, second_number)
3751
answer = input('Your answer: ')
38-
if answer != str(correct_answer):
39-
return f"'{answer}' is wrong answer ;(. Correct answer was '{correct_answer}'\nLet's try again, {name}!"
4052
if answer == str(correct_answer):
4153
number_of_successful_attempts += 1
4254
print('Correct!')
55+
else:
56+
return f"'{answer}' is wrong answer ;(. Correct answer was '{correct_answer}'\nLet's try again, {name}!"
4357
if number_of_successful_attempts == NUMBERS_OF_ATTEMPTS:
4458
return f'Congratulations, {name}!'
466 Bytes
Binary file not shown.

dist/hexlet_code-0.1.0.tar.gz

725 Bytes
Binary file not shown.

pyproject.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,5 @@ build-backend = "poetry.core.masonry.api"
2525
[tool.poetry.scripts]
2626
brain-games = "brain_games.scripts.games.brain_games:main"
2727
brain-even = "brain_games.scripts.games.brain_even:main"
28-
brain-calc = "brain_games.scripts.games.brain_calc:main"
28+
brain-calc = "brain_games.scripts.games.brain_calc:main"
29+
brain-gcd = "brain_games.scripts.games.brain_gcd:main"

0 commit comments

Comments
 (0)