Hello!
Here the computer comes up with a number in range(1, 9), and we try to guess it, until we come up with the correct number.
We can exit anytime during the game and also at the end we have the choice to play again.
Thank you for reading.
Here the computer comes up with a number in range(1, 9), and we try to guess it, until we come up with the correct number.
We can exit anytime during the game and also at the end we have the choice to play again.
import random def guessing(): computer = random.randint(1, 9) number_of_guesses = 0 while True: number_of_guesses += 1 pick = input("Guess, if you dare: ") if pick.lower() == "exit": print("Better luck next time!") print("Attempts:", number_of_guesses - 1) break elif int(pick) > computer: print("Too high.") elif int(pick) < computer: print("Too low.") elif int(pick) == computer: print("Yes!") if number_of_guesses == 1: print("Are you God?!") elif number_of_guesses < 3: print(f"Impressive! Only {number_of_guesses} attemps.") else: print(f"Finally! After {number_of_guesses} attemps.") break again() def again(): if input("Continue?(y/n) ") == 'y': guessing() else: exit guessing()I've been told that I don't need to define a separate function for just asking the user if they want to play again. But I can't seem combine the two functions together.

Thank you for reading.