Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
.venv
/.venv
.idea
/env
/env
/dist
.DS_Store
/brain_games/.DS_Store
brain_games/__pycache__
brain_games/scripts/__pycache__/brain_even.cpython-38.pyc
brain_games/scripts/__pycache__/brain_prime.cpython-38.pyc
Binary file modified brain_games/__pycache__/__init__.cpython-38.pyc
Binary file not shown.
Binary file modified brain_games/__pycache__/check_answer.cpython-38.pyc
Binary file not shown.
Binary file modified brain_games/__pycache__/cli.cpython-38.pyc
Binary file not shown.
Binary file added brain_games/__pycache__/congrats.cpython-38.pyc
Binary file not shown.
Binary file added brain_games/__pycache__/main_flow.cpython-38.pyc
Binary file not shown.
8 changes: 8 additions & 0 deletions brain_games/congrats.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
"Print congrats"


def congrats_or_fail(counter, name):
if counter == 3:
print('Congratulations, {}!'.format(name))
if counter == -1:
print("Let\'s try again, {}!".format(name))
19 changes: 19 additions & 0 deletions brain_games/main_flow.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
"""Main flow."""

from brain_games.cli import welcome_user
from brain_games.check_answer import check_answer
from brain_games.congrats import congrats_or_fail


def flow(open_phrase, game):
"""Main flow of each game
"""
name = welcome_user()
print(open_phrase)
counter = 0
while counter < 3:
user_answer, correct_answer = game()
counter = check_answer(user_answer, correct_answer, counter)
congrats_or_fail(counter, name)
if counter == -1:
break
Binary file modified brain_games/scripts/__pycache__/__init__.cpython-38.pyc
Binary file not shown.
Binary file modified brain_games/scripts/__pycache__/brain_even.cpython-38.pyc
Binary file not shown.
Binary file modified brain_games/scripts/__pycache__/brain_prime.cpython-38.pyc
Binary file not shown.
22 changes: 5 additions & 17 deletions brain_games/scripts/brain_calc.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
import prompt
import random
import operator

from brain_games.cli import welcome_user
from brain_games.check_answer import check_answer
from brain_games.main_flow import flow


def print_random_expression():
Expand All @@ -23,22 +21,12 @@ def print_random_expression():


def main():
"""Calculator Game function.
"""Parity Game function.
Print task three times
"""
name = welcome_user()
print('What is the result of the expression?')
counter = 0
n_times = 0
while n_times < 3:
user_answer, correct_answer = print_random_expression()
counter = check_answer(user_answer, correct_answer, counter)
n_times += 1
if counter == 3:
print('Congratulations, {}!'.format(name))
if counter == -1:
print("Let\'s try again, {}!".format(name))
break
open_phrase = 'What is the result of the expression?'
game = print_random_expression
flow(open_phrase, game)


if __name__ == '__main__':
Expand Down
21 changes: 5 additions & 16 deletions brain_games/scripts/brain_even.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@

import prompt
import random
from brain_games.cli import welcome_user
from brain_games.check_answer import check_answer
from brain_games.main_flow import flow


def even_number(number):
Expand Down Expand Up @@ -33,20 +32,10 @@ def main():
"""Parity Game function.
Print task three times
"""
name = welcome_user()
print('Answer "yes" if the number is even, otherwise answer "no".')
counter = 0
n_times = 0
while n_times < 3:
user_answer, correct_answer = print_random_number()
counter = check_answer(user_answer, correct_answer, counter)
n_times += 1
if counter == 3:
print('Congratulations, {}!'.format(name))
if counter == -1:
print("Let\'s try again, {}!".format(name))
break
open_phrase = 'Answer "yes" if the number is even, otherwise answer "no".'
game = print_random_number
flow(open_phrase, game)


if __name__ == '__main__':
main()
main()
22 changes: 5 additions & 17 deletions brain_games/scripts/brain_gcd.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
import prompt
import random
import math

from brain_games.cli import welcome_user
from brain_games.check_answer import check_answer
from brain_games.main_flow import flow


def print_random_gcd():
Expand All @@ -19,22 +17,12 @@ def print_random_gcd():


def main():
"""Calculator Game function.
"""Greatest common divisor Game function.
Print task three times
"""
name = welcome_user()
print('Find the greatest common divisor of given numbers.')
counter = 0
n_times = 0
while n_times < 3:
user_answer, correct_answer = print_random_gcd()
counter = check_answer(user_answer, correct_answer, counter)
n_times += 1
if counter == 3:
print('Congratulations, {}!'.format(name))
if counter == -1:
print("Let\'s try again, {}!".format(name))
break
open_phrase = 'Find the greatest common divisor of given numbers.'
game = print_random_gcd
flow(open_phrase, game)


if __name__ == '__main__':
Expand Down
22 changes: 5 additions & 17 deletions brain_games/scripts/brain_prime.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
import prompt
import random
import math

from brain_games.cli import welcome_user
from brain_games.check_answer import check_answer
from brain_games.main_flow import flow


def is_prime(number):
Expand Down Expand Up @@ -36,22 +34,12 @@ def print_random_number():


def main():
"""Calculator Game function.
"""Prime Game function.
Print task three times
"""
name = welcome_user()
print('Answer "yes" if given number is prime. Otherwise answer "no".')
counter = 0
n_times = 0
while n_times < 3:
user_answer, correct_answer = print_random_number()
counter = check_answer(user_answer, correct_answer, counter)
n_times += 1
if counter == 3:
print('Congratulations, {}!'.format(name))
if counter == -1:
print("Let\'s try again, {}!".format(name))
break
open_phrase = 'Answer "yes" if given number is prime. Otherwise answer "no".'
game = print_random_number
flow(open_phrase, game)


if __name__ == '__main__':
Expand Down
22 changes: 5 additions & 17 deletions brain_games/scripts/brain_progression.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@

import prompt
import random

from brain_games.cli import welcome_user
from brain_games.check_answer import check_answer
from brain_games.main_flow import flow


def print_random_progression():
Expand All @@ -26,22 +24,12 @@ def print_random_progression():


def main():
"""Calculator Game function.
"""Progression Game function.
Print task three times
"""
name = welcome_user()
print('What number is missing in the progression?')
counter = 0
n_times = 0
while n_times < 3:
user_answer, correct_answer = print_random_progression()
counter = check_answer(user_answer, correct_answer, counter)
n_times += 1
if counter == 3:
print('Congratulations, {}!'.format(name))
if counter == -1:
print("Let\'s try again, {}!".format(name))
break
open_phrase = 'What number is missing in the progression?'
game = print_random_progression
flow(open_phrase, game)


if __name__ == '__main__':
Expand Down