diff --git a/.gitignore b/.gitignore index 26a5fe1..196f506 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,10 @@ .venv /.venv .idea -/env \ No newline at end of file +/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 \ No newline at end of file diff --git a/brain_games/__pycache__/__init__.cpython-38.pyc b/brain_games/__pycache__/__init__.cpython-38.pyc index 9344e88..760cdc8 100644 Binary files a/brain_games/__pycache__/__init__.cpython-38.pyc and b/brain_games/__pycache__/__init__.cpython-38.pyc differ diff --git a/brain_games/__pycache__/check_answer.cpython-38.pyc b/brain_games/__pycache__/check_answer.cpython-38.pyc index 8cf979e..6384911 100644 Binary files a/brain_games/__pycache__/check_answer.cpython-38.pyc and b/brain_games/__pycache__/check_answer.cpython-38.pyc differ diff --git a/brain_games/__pycache__/cli.cpython-38.pyc b/brain_games/__pycache__/cli.cpython-38.pyc index 84cfc66..ccd1d2d 100644 Binary files a/brain_games/__pycache__/cli.cpython-38.pyc and b/brain_games/__pycache__/cli.cpython-38.pyc differ diff --git a/brain_games/__pycache__/congrats.cpython-38.pyc b/brain_games/__pycache__/congrats.cpython-38.pyc new file mode 100644 index 0000000..90c932b Binary files /dev/null and b/brain_games/__pycache__/congrats.cpython-38.pyc differ diff --git a/brain_games/__pycache__/main_flow.cpython-38.pyc b/brain_games/__pycache__/main_flow.cpython-38.pyc new file mode 100644 index 0000000..78cf453 Binary files /dev/null and b/brain_games/__pycache__/main_flow.cpython-38.pyc differ diff --git a/brain_games/congrats.py b/brain_games/congrats.py new file mode 100644 index 0000000..3d71911 --- /dev/null +++ b/brain_games/congrats.py @@ -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)) \ No newline at end of file diff --git a/brain_games/main_flow.py b/brain_games/main_flow.py new file mode 100644 index 0000000..f0b213a --- /dev/null +++ b/brain_games/main_flow.py @@ -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 diff --git a/brain_games/scripts/__pycache__/__init__.cpython-38.pyc b/brain_games/scripts/__pycache__/__init__.cpython-38.pyc index 75c849e..0f6ecb9 100644 Binary files a/brain_games/scripts/__pycache__/__init__.cpython-38.pyc and b/brain_games/scripts/__pycache__/__init__.cpython-38.pyc differ diff --git a/brain_games/scripts/__pycache__/brain_even.cpython-38.pyc b/brain_games/scripts/__pycache__/brain_even.cpython-38.pyc index da572b3..b09b8a7 100644 Binary files a/brain_games/scripts/__pycache__/brain_even.cpython-38.pyc and b/brain_games/scripts/__pycache__/brain_even.cpython-38.pyc differ diff --git a/brain_games/scripts/__pycache__/brain_prime.cpython-38.pyc b/brain_games/scripts/__pycache__/brain_prime.cpython-38.pyc index ada39dd..07d4fa1 100644 Binary files a/brain_games/scripts/__pycache__/brain_prime.cpython-38.pyc and b/brain_games/scripts/__pycache__/brain_prime.cpython-38.pyc differ diff --git a/brain_games/scripts/brain_calc.py b/brain_games/scripts/brain_calc.py index 7a55403..f094ad6 100644 --- a/brain_games/scripts/brain_calc.py +++ b/brain_games/scripts/brain_calc.py @@ -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(): @@ -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__': diff --git a/brain_games/scripts/brain_even.py b/brain_games/scripts/brain_even.py index 305bfd4..3688185 100644 --- a/brain_games/scripts/brain_even.py +++ b/brain_games/scripts/brain_even.py @@ -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): @@ -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() \ No newline at end of file diff --git a/brain_games/scripts/brain_gcd.py b/brain_games/scripts/brain_gcd.py index fcf48f4..4f807e9 100644 --- a/brain_games/scripts/brain_gcd.py +++ b/brain_games/scripts/brain_gcd.py @@ -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(): @@ -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__': diff --git a/brain_games/scripts/brain_prime.py b/brain_games/scripts/brain_prime.py index e94e10f..c858c62 100644 --- a/brain_games/scripts/brain_prime.py +++ b/brain_games/scripts/brain_prime.py @@ -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): @@ -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__': diff --git a/brain_games/scripts/brain_progression.py b/brain_games/scripts/brain_progression.py index d1ec969..cadcfb6 100644 --- a/brain_games/scripts/brain_progression.py +++ b/brain_games/scripts/brain_progression.py @@ -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(): @@ -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__':