Skip to content

Commit 420ed2f

Browse files
committed
add fifth step
1 parent d9cc3e7 commit 420ed2f

File tree

6 files changed

+209
-0
lines changed

6 files changed

+209
-0
lines changed

.README.md.swp

-1 KB
Binary file not shown.

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,5 @@
44
### CodeClimate
55
[![Maintainability](https://api.codeclimate.com/v1/badges/487e17fe16141caa4b2a/maintainability)](https://codeclimate.com/github/s-gala/python-project-49/maintainability)
66

7+
### Asciinema even
8+
[![Demo](https://asciinema.org/a/2FfeOCm4Dq9QOqLXP9wKoP7lt)

brain_games/for_brain_even.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import prompt
2+
from random import randint
3+
4+
name = ''
5+
6+
7+
def welcome_user():
8+
def name_user():
9+
global name
10+
name = prompt.string('May I have your name? ')
11+
name_user()
12+
print(f'Hello, {name}!')
13+
print('Answer "yes" if the number is even, otherwise answer "no".')
14+
15+
16+
def game_even():
17+
for _ in range(1, 4):
18+
random_number = randint(1, 100)
19+
print('Question: ' + str(random_number))
20+
answer = prompt.string('Your answer: ')
21+
right_answer = ''
22+
if random_number % 2 == 0:
23+
right_answer = 'yes'
24+
else:
25+
right_answer = 'no'
26+
if right_answer != answer:
27+
print(f"'{answer}' is wrong answer ;(. ", end=' ')
28+
print(f"Correct answer was '{right_answer}'.")
29+
print(f'Let\'s try again, {name}!')
30+
break
31+
else:
32+
print('Correct!')
33+
else:
34+
print('Congratulations, ' + name + '!')

brain_games/scripts/brain_even.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/usr/bin/env python3
2+
3+
4+
def main():
5+
print('Welcome to the Brain Games!')
6+
from .. import for_brain_even
7+
for_brain_even.welcome_user()
8+
for_brain_even.game_even()
9+
10+
11+
if __name__ == '__main__':
12+
main()

0 commit comments

Comments
 (0)