Skip to content

Commit 3892497

Browse files
committed
refactor: add utils.py and game_logic.py
1 parent 46c9003 commit 3892497

File tree

4 files changed

+24
-14
lines changed

4 files changed

+24
-14
lines changed

brain_games/game_logic.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
def is_even(number: int) -> bool:
2+
if number % 2 == 0:
3+
return True
4+
else:
5+
return False

brain_games/scripts/brain_even.py

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@
22

33
import prompt
44

5+
from brain_games.game_logic import is_even
6+
from brain_games.utils import greet_and_ask_name
7+
58

69
def main():
7-
print('Welcome to the Brain Games!')
8-
name = prompt.string("May I have your name? ")
9-
print(f"Hello, {name}! "
10-
f"Answer \'yes\' if the number is even, otherwise answer \'no\'.")
10+
name = greet_and_ask_name()
11+
print("Answer 'yes' if the number is even, otherwise answer 'no'.")
1112
for i in range(3):
1213
number = random.randint(0, 100)
1314
print(f"Question: {number}")
@@ -16,20 +17,13 @@ def main():
1617
if answer == right_answer:
1718
print('Correct!')
1819
else:
19-
print(f"'{answer}' is wrong answer "
20-
f";(. Correct answer was '{right_answer}'.\n"
20+
print(f"'{answer}' is wrong answer ;(. "
21+
f"Correct answer was '{right_answer}'.\n"
2122
f"Let\'s try again, {name}!")
2223
break
2324
else:
2425
print(f"Congratulations, {name}!")
2526

2627

27-
def is_even(number: int) -> bool:
28-
if number % 2 == 0:
29-
return True
30-
else:
31-
return False
32-
33-
3428
if __name__ == '__main__':
3529
main()

brain_games/scripts/brain_games.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
def main():
77
print("Welcome to the Brain Games!")
88
name = prompt.string("May I have your name? ")
9-
print(cli.wecome_user(name))
9+
print(cli.welcome_user(name))
1010

1111

1212
if __name__ == '__main__':

brain_games/utils.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import prompt
2+
3+
GREETING: str = "Welcome to the Brain Games!"
4+
QUESTION: str = "May I have your name? "
5+
6+
7+
def greet_and_ask_name(msg_greeting=GREETING, msg_question=QUESTION) -> str:
8+
print(msg_greeting)
9+
name = prompt.string(msg_question)
10+
print(f"Hello, {name}! ")
11+
return name

0 commit comments

Comments
 (0)