Skip to content

Commit c6cbfa7

Browse files
committed
change code even
1 parent 7d71635 commit c6cbfa7

File tree

3 files changed

+31
-29
lines changed

3 files changed

+31
-29
lines changed

brain_games/game_is_evens.py

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

3-
from brain_games.q_and_a import quest_answer
4-
5-
6-
def which_evens(name):
7-
print('Answer "yes" if the number is even, otherwise answer "no".')
8-
9-
for _ in range(3):
10-
number = randint(1, 50)
11-
if number % 2 == 0:
12-
check = "yes"
13-
else:
14-
check = "no"
15-
16-
quest = f"Question: {number}"
17-
answer = quest_answer(quest, check, name)
18-
if answer == "mistake":
19-
break
203

4+
def which_evens():
5+
greet = 'Answer "yes" if the number is even, otherwise answer "no".'
6+
number = randint(1, 50)
7+
if number % 2 == 0:
8+
check = "yes"
219
else:
22-
print(f"Congratulations, {name}!")
10+
check = "no"
11+
quest = f"Question: {number}"
12+
return greet, quest, check

brain_games/q_and_a.py

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

33

4-
def quest_answer(quest, check, name):
5-
print(quest)
6-
answer = prompt.string("Your answer: ")
7-
if answer == check:
8-
print("Correct!")
4+
def quest_answer(func):
5+
print("Welcome to the Brain Games!")
6+
nick = prompt.string("May I have your name? ")
7+
print(f"Hello, {nick}")
8+
count = 0
9+
for _ in range(3):
10+
greet, quest, check = func()
11+
if count == 0:
12+
print(greet)
13+
count = 1
14+
print(quest)
15+
answer = prompt.string("Your answer: ")
16+
if answer == check:
17+
print("Correct!")
918

19+
else:
20+
print(
21+
f'"{answer}" is wrong answer ;(. Correct answer was "{check}".'
22+
)
23+
print(f"Let's try again, {nick}!")
24+
break
1025
else:
11-
print(f'"{answer}" is wrong answer ;(. Correct answer was "{check}".')
12-
print(f"Let's try again, {name}!")
13-
return "mistake"
26+
print(f"Congratulations, {nick}")

brain_games/scripts/brain_even.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
from brain_games.game_is_evens import which_evens
2-
from brain_games.greet_name import greet_and_name
2+
from brain_games.q_and_a import quest_answer
33

44

55
def main():
6-
name = greet_and_name()
7-
which_evens(name)
6+
quest_answer(which_evens)
87

98

109
if __name__ == "__main__":

0 commit comments

Comments
 (0)