Skip to content

Commit 66cbf61

Browse files
committed
добавлена игра на чётность
1 parent df35d8c commit 66cbf61

File tree

5 files changed

+33
-0
lines changed

5 files changed

+33
-0
lines changed
7 Bytes
Binary file not shown.

brain_games/cli.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@
44
def welcome_user():
55
name = prompt.string('May I have your name? ')
66
print(f'Hello, {name}!')
7+
return name
1.43 KB
Binary file not shown.
-2 Bytes
Binary file not shown.

brain_games/scripts/brain_even.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
from random import randrange
2+
from brain_games.cli import welcome_user
3+
from brain_games.scripts.brain_games import greet
4+
import prompt
5+
6+
7+
def parity_check():
8+
name = welcome_user()
9+
print('Answer "yes" if the number is even, otherwise answer "no".')
10+
11+
answer = 0
12+
while answer < 3:
13+
n = randrange(1, 100)
14+
print(f'Question: {n}')
15+
user_answer = prompt.string('Your answer: ')
16+
correct = 'yes' if n % 2 == 0 else 'no'
17+
if user_answer == correct:
18+
print('Correct!')
19+
answer += 1
20+
else:
21+
print(f"'{user_answer}' is wrong answer ;(. Correct answer was '{correct}'.\nLet's try again, {name}!")
22+
break
23+
if answer == 3:
24+
print(f'Congratulations, {name}')
25+
26+
27+
def main():
28+
greet()
29+
parity_check()
30+
31+
if __name__ == '__main__':
32+
main()

0 commit comments

Comments
 (0)