Skip to content

Commit ecd1ce1

Browse files
author
Виталий
committed
Second correction accordance with the recommendations
1 parent 550781e commit ecd1ce1

File tree

11 files changed

+42
-64
lines changed

11 files changed

+42
-64
lines changed

brain_games/engine_game.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
import prompt
22

3+
NUMBER_QUESTIONS = 3
34

4-
def run_game(displays_rules_game, generating_question_and_answer):
5-
NUMBER_QUESTIONS = 3
5+
6+
def run_game(RULES_GAME, generating_question_and_answer):
67
print('Welcome to the Brain Games!')
78
name = prompt.string('May I have your name? ')
89
print(f'Hello, {name}!')
9-
displays_rules_game()
10+
print(RULES_GAME)
1011
for _ in range(NUMBER_QUESTIONS):
1112
question, right_answer = generating_question_and_answer()
1213
print(f"Question: {question}")
1314
response_user = prompt.string('Your answer: ')
14-
if response_user == right_answer:
15-
print('Correct!')
16-
else:
15+
if response_user != right_answer:
1716
print(f"'{response_user}' is wrong answer ;(. ", end='')
1817
print(f"Correct answer was '{right_answer}'.")
1918
print(f"Let's try again, {name}!")
2019
return
21-
print(f"Congratulations, {name}!")
20+
print('Correct!')
21+
print(f"Congratulations, {name}!")

brain_games/games/calc.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
from random import choice, randint
22

3+
MIN_GEN_RANGE = 1
4+
MAX_GEN_RANGE = 25
5+
OPERATIONS = ('+', '-', '*')
6+
RULES_GAME = "What is the result of the expression?"
37

4-
def displays_rules_game():
5-
print("What is the result of the expression?")
68

7-
8-
def generating_question_and_answer():
9-
MIN_GEN_RANGE = 1
10-
MAX_GEN_RANGE = 25
9+
def generating_question_and_answer():
1110
num1 = randint(MIN_GEN_RANGE, MAX_GEN_RANGE)
1211
num2 = randint(MIN_GEN_RANGE, MAX_GEN_RANGE)
13-
operation = choice('+-*')
12+
operation = choice(OPERATIONS)
1413
question = f"{str(num1)} {operation} {str(num2)}"
1514
match operation:
1615
case "+":

brain_games/games/even.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
from random import randint
22

3-
4-
def displays_rules_game():
5-
print('Answer "yes" if the number is even, otherwise answer "no".')
3+
MIN_GEN_RANGE = 1
4+
MAX_GEN_RANGE = 100
5+
RULES_GAME = 'Answer "yes" if the number is even, otherwise answer "no".'
66

77

88
def generating_question_and_answer():
9-
MIN_GEN_RANGE = 1
10-
MAX_GEN_RANGE = 100
119
number = randint(MIN_GEN_RANGE, MAX_GEN_RANGE)
1210
question = str(number)
1311
if number % 2 == 0:

brain_games/games/gcd.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
from random import randint
22

3+
MIN_GEN_RANGE = 2
4+
MAX_GEN_RANGE = 10
5+
RULES_GAME = "Find the greatest common divisor of given numbers."
6+
37

48
def finding_gcd(num1, num2): # нахождение наибольшего общего делителя
59
while num1 != 0 and num2 != 0:
@@ -10,13 +14,7 @@ def finding_gcd(num1, num2): # нахождение наибольшего
1014
return (num1 + num2)
1115

1216

13-
def displays_rules_game():
14-
print("Find the greatest common divisor of given numbers.")
15-
16-
1717
def generating_question_and_answer():
18-
MIN_GEN_RANGE = 2
19-
MAX_GEN_RANGE = 10
2018
num1 = randint(MIN_GEN_RANGE, MAX_GEN_RANGE)
2119
num2 = randint(MIN_GEN_RANGE, MAX_GEN_RANGE)
2220
question = f"{num1} {num2}"

brain_games/games/prime.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
from random import randint
22

3+
MIN_GEN_RANGE = 1
4+
MAX_GEN_RANGE = 130
5+
RULES_GAME = 'Answer "yes" if given number is prime. Otherwise answer "no".'
6+
37

48
# функция проверяет является ли число простым
59
# если число простое -> True
@@ -13,13 +17,7 @@ def is_prime(number):
1317
return True
1418

1519

16-
def displays_rules_game():
17-
print('Answer "yes" if given number is prime. Otherwise answer "no".')
18-
19-
2020
def generating_question_and_answer():
21-
MIN_GEN_RANGE = 1
22-
MAX_GEN_RANGE = 130
2321
number = randint(MIN_GEN_RANGE, MAX_GEN_RANGE)
2422
question = str(number)
2523
if is_prime(number):

brain_games/games/progression.py

Lines changed: 8 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,22 @@
11
from random import randint
22

3-
4-
# функция создает арифметическую прогрессию
5-
def generating_a_progression(first: int, step: int, empty: int) -> str:
6-
question = ''
7-
for i in range(1, 11):
8-
if i == empty:
9-
question += '.. '
10-
else:
11-
question += str(first + step * (i - 1)) + ' '
12-
question = question.strip()
13-
return (question)
14-
15-
16-
def displays_rules_game():
17-
print("What number is missing in the progression?")
3+
LEN_PROGRESSION = 10
4+
MIN_GEN_RANGE = 1
5+
MAX_GEN_RANGE = 50
6+
RULES_GAME = "What number is missing in the progression?"
187

198

209
def generating_question_and_answer():
21-
LEN_PROGRESSION = 10
22-
MIN_GEN_RANGE = 1
23-
MAX_GEN_RANGE = 50
24-
#
2510
first_element = randint(MIN_GEN_RANGE, MAX_GEN_RANGE)
2611
step = randint(MIN_GEN_RANGE, MAX_GEN_RANGE)
2712
index_of_missing_element = randint(MIN_GEN_RANGE, LEN_PROGRESSION)
2813
#
2914
answer = str(first_element + step * (index_of_missing_element - 1))
30-
question = ''
15+
question = []
3116
for i in range(LEN_PROGRESSION):
3217
if i + 1 == index_of_missing_element:
33-
question += '.. '
18+
question.append('..')
3419
else:
35-
question += str(first_element + step * i) + ' '
36-
question = question.strip()
20+
question.append(str(first_element + step * i))
21+
question = ' '.join(question)
3722
return ((question, answer))

brain_games/scripts/brain_calc.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
from brain_games.engine_game import run_game
22
from brain_games.games.calc import (
3-
displays_rules_game,
3+
RULES_GAME,
44
generating_question_and_answer,
55
)
66

77

88
def main():
9-
run_game(displays_rules_game, generating_question_and_answer)
9+
run_game(RULES_GAME, generating_question_and_answer)
1010

1111

1212
if __name__ == '__main__':

brain_games/scripts/brain_even.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
from brain_games.engine_game import run_game
22
from brain_games.games.even import (
3-
displays_rules_game,
3+
RULES_GAME,
44
generating_question_and_answer,
55
)
66

77

88
def main():
9-
run_game(displays_rules_game, generating_question_and_answer)
9+
run_game(RULES_GAME, generating_question_and_answer)
1010

1111

1212
if __name__ == '__main__':

brain_games/scripts/brain_gcd.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
from brain_games.engine_game import run_game
22
from brain_games.games.gcd import (
3-
displays_rules_game,
3+
RULES_GAME,
44
generating_question_and_answer,
55
)
66

77

88
def main():
9-
run_game(displays_rules_game, generating_question_and_answer)
9+
run_game(RULES_GAME, generating_question_and_answer)
1010

1111

1212
if __name__ == '__main__':

brain_games/scripts/brain_prime.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
from brain_games.engine_game import run_game
22
from brain_games.games.prime import (
3-
displays_rules_game,
3+
RULES_GAME,
44
generating_question_and_answer,
55
)
66

77

88
def main():
9-
run_game(displays_rules_game, generating_question_and_answer)
9+
run_game(RULES_GAME, generating_question_and_answer)
1010

1111

1212
if __name__ == '__main__':

0 commit comments

Comments
 (0)