Skip to content

Commit f08ae52

Browse files
committed
add new module start_game.py
1 parent 44a92c7 commit f08ae52

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

brain_games/games/start_game.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
2+
3+
import prompt
4+
from brain_games.games.check_even import check_even
5+
from brain_games.games.calculator import calculator
6+
7+
8+
def start_game():
9+
print('Welcome to the Brain Games!')
10+
user_name = prompt.string("May I have your name? ")
11+
print(f"Hello, {user_name}!")
12+
number_game = prompt.integer('Choose a game: 1 - "checking for parity", 2 - "calculator" ')
13+
14+
15+
games = {1: check_even, 2: calculator}
16+
game_func = games.get(number_game)
17+
18+
if number_game == 1:
19+
print('Answer "yes" if the number is even, otherwise answer "no".')
20+
elif number_game == 2:
21+
print('What is the result of the expression?')
22+
elif number_game not in games:
23+
print("There is no such number\nLet's try again, {user_name}!")
24+
25+
26+
correct_answers_count = 0
27+
28+
while correct_answers_count < 3:
29+
random_number, correct_answer = game_func()
30+
print(f'Question: {random_number}')
31+
user_answer = input("Your answer: ")
32+
33+
if user_answer == correct_answer:
34+
print('Correct!')
35+
correct_answers_count += 1
36+
else:
37+
print(f"'{user_answer}' is wrong answer ;(. Correct answer was '{correct_answer}'.\nLet's try again, {user_name}!")
38+
break
39+
40+
if correct_answers_count == 3:
41+
print(f'Congratulations, {user_name}!')

0 commit comments

Comments
 (0)