Skip to content

Commit 157a165

Browse files
committed
chenges 2-nd check
1 parent 8a4e688 commit 157a165

File tree

7 files changed

+40
-56
lines changed

7 files changed

+40
-56
lines changed

brain_games/games/brain_calc.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
1-
import brain_games.sample
1+
from brain_games.sample import samples
2+
import random
23

34

45
CON_ANSWER = 'What is the result of the expression?'
56

67

7-
def type_brain_calc(first_number, sec_number, arithmetic_operation):
8+
def type_brain_calc():
89
correct_answer = ''
10+
first_number = random.randint(1, 25)
11+
sec_number = random.randint(1, 25)
12+
arithmetic_operation = random.choice(['+', '-', '*'])
913
match arithmetic_operation:
1014
case '+':
1115
correct_answer = first_number + sec_number
@@ -18,7 +22,8 @@ def type_brain_calc(first_number, sec_number, arithmetic_operation):
1822

1923

2024
def main():
21-
brain_games.sample.samples('brain-calc', CON_ANSWER)
25+
samples(CON_ANSWER, type_brain_calc(),
26+
type_brain_calc(), type_brain_calc())
2227

2328

2429
if __name__ == '__main__':

brain_games/games/brain_even.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
1-
import brain_games.sample
1+
from brain_games.sample import samples
2+
import random
23

34

45
CON_ANSWER = 'Answer "yes" if the number is even, otherwise answer "no".'
56

67

7-
def type_brain_even(first_number):
8+
def type_brain_even():
9+
first_number = random.randint(1, 50)
810
corr_ans = 'yes' if first_number % 2 == 0 else 'no'
911
return (corr_ans,
1012
f'Question: {first_number}')
1113

1214

1315
def main():
14-
brain_games.sample.samples('brain-even', CON_ANSWER)
16+
samples(CON_ANSWER, type_brain_even(),
17+
type_brain_even(), type_brain_even())
1518

1619

1720
if __name__ == '__main__':

brain_games/games/brain_gcd.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
from brain_games.sample import samples
2+
import random
23

34

45
CON_ANSWER = 'Find the greatest common divisor of given numbers.'
56

67

7-
def type_brain_gcd(frs_num, sec_num):
8+
def type_brain_gcd():
9+
frs_num = random.randint(1, 50)
10+
sec_num = random.randint(1, 50)
811
re = []
912
max_num = max(frs_num, sec_num)
1013
for i in range(1, max_num + 1):
@@ -15,7 +18,8 @@ def type_brain_gcd(frs_num, sec_num):
1518

1619

1720
def main():
18-
samples('brain-gcd', CON_ANSWER)
21+
samples(CON_ANSWER, type_brain_gcd(),
22+
type_brain_gcd(), type_brain_gcd())
1923

2024

2125
if __name__ == '__main__':

brain_games/games/brain_prime.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
from brain_games.sample import samples
2+
import random
23

34

45
CON_ANSWER = 'Answer "yes" if given number is prime. Otherwise answer "no".'
56

67

7-
def type_brain_prime(num):
8+
def type_brain_prime():
9+
num = random.randint(1, 50)
810
re = []
911
for i in range(1, num + 1):
1012
if num % i == 0:
@@ -15,7 +17,8 @@ def type_brain_prime(num):
1517

1618

1719
def main():
18-
samples('brain-prime', CON_ANSWER)
20+
samples(CON_ANSWER, type_brain_prime(),
21+
type_brain_prime(), type_brain_prime())
1922

2023

2124
if __name__ == '__main__':

brain_games/games/brain_progression.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
CON_ANSWER = 'What number is missing in the progression?'
66

77

8-
def type_brain_progression(first_num):
8+
def type_brain_progression():
9+
first_num = random.randint(1, 50)
910
re = []
1011
range_progressing = random.randint(5, 10)
1112
sec_num = random.randint(1, 5)
@@ -22,7 +23,8 @@ def type_brain_progression(first_num):
2223

2324

2425
def main():
25-
samples('brain-progression', CON_ANSWER)
26+
samples(CON_ANSWER, type_brain_progression(),
27+
type_brain_progression(), type_brain_progression())
2628

2729

2830
if __name__ == '__main__':

brain_games/sample.py

Lines changed: 4 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,17 @@
11
import prompt
2-
import random
3-
# import brain_games.scripts.games.brain_calc
4-
# import brain_games.scripts.games.brain_even
5-
# import brain_games.scripts.games.brain_gcd
62

73

84
NUMBERS_OF_ATTEMPTS = 3
95

106

11-
def samples(type_game, condition_answer):
7+
def samples(condition_answer, answ_and_qest, answ_and_qest2, answ_and_qest3):
128
print('Welcome to the Brain Games!')
139
name = prompt.string('May I have your name? ')
1410
print(f'Hello, {name}!')
1511
number_of_successful_attempts = 0
1612
print(condition_answer)
13+
correct_answer, question = answ_and_qest
1714
for _ in range(NUMBERS_OF_ATTEMPTS):
18-
first_number = random.randint(1, 50)
19-
second_number = random.randint(1, 50)
20-
match type_game:
21-
case 'brain-even':
22-
import brain_games.scripts.games.brain_even
23-
correct_answer, question = (
24-
brain_games.scripts.games.
25-
brain_even.type_brain_even(first_number))
26-
case 'brain-calc':
27-
import brain_games.scripts.games.brain_calc
28-
first_number = random.randint(1, 25)
29-
second_number = random.randint(1, 25)
30-
arithmetic_operation = random.choice(['+', '-', '*'])
31-
correct_answer, question = (
32-
brain_games.scripts.games.
33-
brain_calc.type_brain_calc(first_number, second_number,
34-
arithmetic_operation))
35-
case 'brain-gcd':
36-
import brain_games.scripts.games.brain_gcd
37-
correct_answer, question = (
38-
brain_games.scripts.games.
39-
brain_gcd.type_brain_gcd(first_number, second_number))
40-
case 'brain-progression':
41-
import brain_games.scripts.games.brain_progression
42-
correct_answer, question = (
43-
brain_games.scripts.games.
44-
brain_progression.type_brain_progression(first_number))
45-
case 'brain-prime':
46-
import brain_games.scripts.games.brain_prime
47-
correct_answer, question = (
48-
brain_games.scripts.games.
49-
brain_prime.type_brain_prime(first_number))
5015
print(question)
5116
answer = input('Your answer: ')
5217
if answer == str(correct_answer):
@@ -57,5 +22,7 @@ def samples(type_game, condition_answer):
5722
f" '{correct_answer}'\n"
5823
f"Let's try again, {name}!")
5924
break
25+
correct_answer, question = answ_and_qest3\
26+
if number_of_successful_attempts == 2 else answ_and_qest2
6027
if number_of_successful_attempts == NUMBERS_OF_ATTEMPTS:
6128
print(f'Congratulations, {name}!')

pyproject.toml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "hexlet-code"
3-
version = "0.5.8"
3+
version = "0.5.9"
44
description = "Учебный проект из 6 команд"
55
authors = ["ttehasi <[email protected]>"]
66
readme = "README.md"
@@ -24,9 +24,9 @@ build-backend = "poetry.core.masonry.api"
2424

2525

2626
[tool.poetry.scripts]
27-
brain-games = "brain_games.scripts.games.brain_games:main"
28-
brain-even = "brain_games.scripts.games.brain_even:main"
29-
brain-calc = "brain_games.scripts.games.brain_calc:main"
30-
brain-gcd = "brain_games.scripts.games.brain_gcd:main"
31-
brain-progression = "brain_games.scripts.games.brain_progression:main"
32-
brain-prime = "brain_games.scripts.games.brain_prime:main"
27+
brain-games = "brain_games.games.brain_games:main"
28+
brain-even = "brain_games.games.brain_even:main"
29+
brain-calc = "brain_games.games.brain_calc:main"
30+
brain-gcd = "brain_games.games.brain_gcd:main"
31+
brain-progression = "brain_games.games.brain_progression:main"
32+
brain-prime = "brain_games.games.brain_prime:main"

0 commit comments

Comments
 (0)