-
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
874a0db
commit 5fa152e
Showing
12 changed files
with
94 additions
and
57 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
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 |
---|---|---|
@@ -1,25 +1,23 @@ | ||
import prompt | ||
|
||
|
||
def welcome_user(): | ||
def engine(brain_game): | ||
print('Welcome to the Brain Games!') | ||
global name | ||
name = prompt.string('May I have your name? ') | ||
print(f'Hello, {name}!') | ||
|
||
|
||
def engine(brain_game): | ||
print(brain_game.DESCRIPTION) | ||
count_correct_answers = 0 | ||
while count_correct_answers < 3: | ||
correct_answer = brain_game() | ||
correct_answer = brain_game.generate_round() | ||
user_answer = prompt.string('Your answer: ') | ||
if user_answer == correct_answer: | ||
print('Correct!') | ||
count_correct_answers += 1 | ||
count_correct_answers == 3 | ||
else: | ||
print(f"'{user_answer}' is wrong answer ;(." | ||
f" Correct answer was '{correct_answer}'.") | ||
print(f"Let's try again, {name}!") | ||
break | ||
if count_correct_answers == 3: | ||
else: | ||
print(f"Congratulations, {name}!") |
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 |
---|---|---|
@@ -1,17 +1,33 @@ | ||
from random import randint, choice | ||
|
||
DESCRIPTION = 'What is the result of the expression?' | ||
|
||
def game_calc(): | ||
print('What is the result of the expression?') | ||
|
||
def add(x, y): | ||
return x + y | ||
|
||
|
||
def multiply(x, y): | ||
return x * y | ||
|
||
|
||
def subtraction(x, y): | ||
return x - y | ||
|
||
|
||
def generate_round(): | ||
first_random_number = randint(1, 20) | ||
second_random_number = randint(1, 20) | ||
random_operation = choice('+-*') | ||
if random_operation == '+': | ||
correct_answer = str(first_random_number + second_random_number) | ||
correct_answer =\ | ||
str(add(first_random_number, second_random_number)) | ||
elif random_operation == '-': | ||
correct_answer = str(first_random_number - second_random_number) | ||
correct_answer =\ | ||
str(subtraction(first_random_number, second_random_number)) | ||
elif random_operation == '*': | ||
correct_answer = str(first_random_number * second_random_number) | ||
correct_answer =\ | ||
str(multiply(first_random_number, second_random_number)) | ||
print(f'Question: {first_random_number} {random_operation} ' | ||
f'{second_random_number}') | ||
return correct_answer |
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 |
---|---|---|
@@ -1,9 +1,14 @@ | ||
from random import randint | ||
|
||
DESCRIPTION = 'Answer "yes" if the number is even, otherwise answer "no".' | ||
|
||
def game_even(): | ||
print('Answer "yes" if the number is even, otherwise answer "no".') | ||
|
||
def is_even(number): | ||
return number % 2 == 0 | ||
|
||
|
||
def generate_round(): | ||
random_number = randint(1, 100) | ||
correct_answer = ('yes', 'no')[random_number % 2] | ||
correct_answer = 'yes' if is_even(random_number) else 'no' | ||
print(f'Question: {random_number}') | ||
return correct_answer |
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 |
---|---|---|
@@ -1,13 +1,19 @@ | ||
from random import randint | ||
|
||
DESCRIPTION = 'Find the greatest common divisor of given numbers.' | ||
|
||
def game_gcd(): | ||
print('Find the greatest common divisor of given numbers.') | ||
|
||
def find_divisors(number): | ||
divisors = [i for i in range(1, number + 1) if number % i == 0] | ||
return divisors | ||
|
||
|
||
def generate_round(): | ||
first_random_number = randint(1, 100) | ||
second_random_number = randint(1, 100) | ||
correct_answer = 1 | ||
for i in range(2, min(first_random_number, second_random_number) + 1): | ||
if first_random_number % i == 0 and second_random_number % i == 0: | ||
correct_answer = i | ||
divisors_of_first_random_number = set(find_divisors(first_random_number)) | ||
divisors_of_second_random_number = set(find_divisors(second_random_number)) | ||
correct_answer =\ | ||
max(divisors_of_first_random_number & divisors_of_second_random_number) | ||
print(f'Question: {first_random_number} {second_random_number}') | ||
return str(correct_answer) |
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 |
---|---|---|
@@ -1,13 +1,22 @@ | ||
from random import randint | ||
|
||
DESCRIPTION = 'Answer "yes" if given number is prime. Otherwise answer "no".' | ||
|
||
def game_prime(): | ||
print('Answer "yes" if given number is prime. Otherwise answer "no".') | ||
random_number = randint(3, 100) | ||
correct_answer = 'yes' | ||
for i in range(2, random_number): | ||
if random_number % i == 0: | ||
correct_answer = 'no' | ||
break | ||
|
||
def is_prime(number): | ||
if number >= 2: | ||
if number == 2: | ||
return True | ||
divider = 2 | ||
while number % divider != 0: | ||
divider += 1 | ||
return number == divider | ||
else: | ||
return False | ||
|
||
|
||
def generate_round(): | ||
random_number = randint(2, 100) | ||
correct_answer = 'yes' if is_prime(random_number) else 'no' | ||
print(f'Question: {random_number}') | ||
return correct_answer |
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
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
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
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
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
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