UPDATE: I have added:
- a play-again option
- score keeping thing
- difficulty levels
**(but I still need help with the functions part).
I don't feel it's necessary to explain what my code does, as it is pretty self-explanatory. I have the entire program completed, but I need to put some of the components of the program into functions. I don't know how to do this. I also need to add a play again option (I have done this before, but for some reason this particular code isn't working...).
import random #variables: score = 0 play = True while play: while True: try: difficulty = int(input("Give me a number between 1 and 3 (these are the difficulty levels) \n\n 1 = easy \n 2 = medium \n 3 = hard \n\n")) except: print("This is not a number!") continue if difficulty > 3 or difficulty < 1: print("That's an invalid input, please re-enter your number") continue break number = random.randint(1, 10 * difficulty) attempts = 0 guess = 0 while guess != number and attempts < 3: attempts += 1 print("attempt number " + str(attempts)) while True: try: guess = int(input("Guess what number I am thinking of ")) except: print("That's not a number!") continue if guess > 10 * difficulty or guess < 1: print("That's an invalid input, please re-enter your number.") continue break if guess == number: print("You guessed it correct!") score += 1 elif abs(guess - number) == 1: print("You're hot on the trail!") elif abs(guess - number) <= 3: print("You're getting warmer...") else: print("You're freezing cold!!") if attempts == 3 and guess != number: print("Oops! You've run out of guesses!") print("The number I was thinking of was " + str(number) + ".") print("Your final score is " + str(score)) text = input("If you want to play again, type 'yes' ") if text != "yes": play = False print("Ok, thank you for playing!")