def main(): print(""" Welcome to the Brain Games! What number is missing in the progression?\n""") user_name = cli.get_user_name() attempts = ATTEMPTS while attempts > 0: progression, answer = make_progression() print("Question: {}".format(progression)) user_answer = cli.get_user_answer() engine.run(user_answer, answer, user_name) attempts -= 1
def main(): print(""" Welcome to the Brain Games! Answer "yes" if number even otherwise answer "no"\n""") user_name = cli.get_user_name() attempts = ATTEMPTS while attempts > 0: questions = engine.get_random_number() answer = get_correct_answer(questions) print("Question: {}".format(questions)) user_answer = cli.get_user_answer() engine.run(user_answer, answer, user_name) attempts -= 1
def engine(user_name, play): """Game engine process.""" correct_answers = 0 while correct_answers < NUMBER_OF_ROUNDS: question, correct_answer = play() print(question) res, msg = check_answer(get_user_answer(), correct_answer) print(msg) if not res: print(f"Let's try again, {user_name}!") return correct_answers += 1 print(f'Congratulations, {user_name}!')
def engine(user_name, play): """Game engine.""" counter_answer = 0 while counter_answer < NUMBER_OF_ROUNDS: question, correct_answer = play() print(question) res, message = check_answer(get_user_answer(), correct_answer) print(message) if not res: print(f'Let`s try again, {user_name}') return counter_answer += 1 print(f'Congratulations, {user_name}!')
def run(game): print('Welcome to the Brain Games!\n' f'{game.TASK}\n') name = get_user_name() for _ in range(ROUNDS): question, true_answer = game.get_round() print(f'Question: {question}') answer = get_user_answer() if answer != true_answer: print(f'{answer} is wrong answer ;(. Correct answer' f' was {true_answer}.\n' f'Let\'s try again, {name}!\n') return print('Correct!\n') print(f'Congratulations, {name}!\n')
def main(): print(""" Welcome to the Brain Games! Find the greatest common divisor of given numbers.\n""") user_name = cli.get_user_name() attempts = ATTEMPTS while attempts > 0: number_first = engine.get_random_number() number_second = engine.get_random_number() answer = str(gcd(number_first, number_second)) print("Question: {} {}".format(number_first, number_second)) user_answer = cli.get_user_answer() engine.run(user_answer, answer, user_name) attempts -= 1
def game_engine(user_name: str, game: Callable[[], Tuple[str, str]]) -> None: """Game engine.""" correct_answers = 0 while correct_answers < NUMBER_OF_ROUNDS: question, correct_answer = game() print(question) res, message = check_answer(get_user_answer(), correct_answer) print(message) if res: correct_answers += 1 else: print(f"Let's try again, {user_name}!") return else: print(f'Congratulations, {user_name}!')
def main(): print(""" Welcome to the Brain Games! What is the result of the expression?\n""") user_name = cli.get_user_name() attempts = ATTEMPTS while attempts > 0: num_first = engine.get_random_number() num_second = engine.get_random_number() operation = operation_list[randint(0, len(operation_list) - 1)] answer = get_correct_answer(num_first, num_second, operation) print("Question: {} {} {}".format(num_first, operation, num_second)) user_answer = cli.get_user_answer() engine.run(answer, user_answer, user_name) attempts -= 1
def main(): print(""" Welcome to the Brain Games! Answer "yes" if given number is prime. Otherwise answer "no".\n""") user_name = cli.get_user_name() attempts = ATTEMPTS while attempts > 0: number_prime = engine.get_random_number() if check_prime_number(number_prime) is False: answer = 'no' else: answer = 'yes' print("Questions: {}".format(number_prime)) user_answer = cli.get_user_answer() engine.run(user_answer, answer, user_name) attempts -= 1
def play(game): greet() print_text(game.RULES) user_name = get_user_name() answer_count = 0 while answer_count < ROUNDS_COUNT: question, answer = game.get_question() print_question(question) user_answer = get_user_answer() if user_answer != answer: print_fail_answer(user_answer, answer, user_name) return print_text(RIGHT_ANSWER_TEXT) answer_count += 1 congratulate(user_name)