-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
83595e9
commit 97c443e
Showing
7 changed files
with
61 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,3 +25,6 @@ brain-gcd: | |
|
||
brain-progression: | ||
poetry run brain-progression | ||
|
||
brain-prime: | ||
poetry run brain-prime |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
#!/usr/bin/env python3 | ||
import prompt | ||
from random import randint, choice | ||
|
||
|
||
def welcome_user(): | ||
global name | ||
name = prompt.string('May I have your name? ') | ||
print(f'Hello, {name}!') | ||
|
||
|
||
def greeting(): | ||
print('Welcome to the Brain Games!') | ||
|
||
|
||
def try_again(name): | ||
print(f"Let's try again, {name}!") | ||
|
||
|
||
def congratulations(name): | ||
print(f"Congratulations, {name}!") | ||
|
||
|
||
def brain_prime(): | ||
print('Answer "yes" if given number is prime. Otherwise answer "no".') | ||
count_correct_answers = 0 | ||
while count_correct_answers < 3: | ||
random_number = randint(3, 100) | ||
correct_answer = 'yes' | ||
for i in range(2, random_number): | ||
if random_number % i == 0: | ||
correct_answer = 'no' | ||
break | ||
print(f'Question: {random_number}') | ||
user_answer = prompt.string('Your answer: ') | ||
if user_answer == correct_answer: | ||
print('Correct!') | ||
count_correct_answers += 1 | ||
else: | ||
print(f"'{user_answer}' is wrong answer ;(." | ||
f" Correct answer was '{correct_answer}'.") | ||
try_again(name) | ||
break | ||
if count_correct_answers == 3: | ||
congratulations(name) | ||
|
||
|
||
def main(): | ||
greeting() | ||
welcome_user() | ||
brain_prime() | ||
|
||
|
||
if __name__ == '__main__': | ||
main() |
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters