diff --git a/brain_games/prime_game.py b/brain_games/prime_game.py index ed11fd2..7cf484e 100644 --- a/brain_games/prime_game.py +++ b/brain_games/prime_game.py @@ -3,6 +3,13 @@ from cli import greet_first, welcome_user +def question_prime(): + """Ask the question and return a tuple (number_to_guess, user_answer).""" + number_to_guess = random.randint(1, 100) + user_answer = prompt.string(f'Number: {number_to_guess}\n') + return number_to_guess, user_answer + + def prime_goal(): """Provide information about the goal of the prime game to the user.""" print('Answer "yes" if given number is prime. Otherwise answer "no".\n') @@ -17,8 +24,7 @@ def is_prime(number): def prime_game(name): """Brain game prime logic.""" for _ in range(3): - random_number = random.randint(1, 100) - user_answer = prompt.string(f'Number: {random_number}\n') + random_number, user_answer = question_prime() prime_status = is_prime(random_number) expected_answer = 'yes' if prime_status else 'no'