I want to make the "continue playing" user input to only appear when all the tries are exhausted in the guessing game.
from random import random, randint
import random
#Guessing Game
attempts = 5
print("===GUESS THE NUMBER===")
print(f"GAME OBJECTIVE: Guess the computer's number in {attempts} tries")
running = True
computerNum = random.randint(1,15)
while running == True:
guess = int(input("Guess the number:\n>"))
print("\n")
if guess > computerNum:
print("Lower...")
attempts -= 1
print(f"[You have {attempts} tries left]")
if guess < computerNum:
print("Higher...")
attempts -= 1
print(f"[You have {attempts} tries left]")
if attempts == 0:
print("GAME OVER!!!")
print(f"The computer's number is {computerNum}")
break
if guess == computerNum:
print("You have guessed the number!!!")
print("YOU WIN!!!")
break
print("\n")
playAgain = input("Do you want to continue playing(Y/N):\n")
if playAgain in ("N","n"):
break
The problem with this code now is just that each time you guess the number, it keeps asking if you want to continue playing.
Also, I want the console to print "Not a number" each time anything apart from a number is input.
if guess != int():
print("Enter a number")
This is my rough idea so far but I keep getting error messages
I am a beginner by the way