User Input only at the end of while loop
You can handle user input that is not a number as shown in https://www.geeksforgeeks.org/python-int-function/.
You should not use break
when the user wins or loses.
If you use it, the user is not able to play the game again.
To prevent the program from asking every time whether the user wants to play again, you have to check again for remaining tries if attempts == 0 or guess == computerNum
.
from random import random
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:
try:
guess = int(input("Guess the number:\n>"))
except ValueError as e:
print("Enter a number")
continue
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}")
if guess == computerNum:
print("You have guessed the number!!!")
print("YOU WIN!!!")
if attempts == 0 or guess == computerNum:
print("\n")
playAgain = input("Do you want to continue playing(Y/N):\n")
if playAgain in ("N", "n"):
break
else:
computerNum = random.randint(1, 15)
attempts = 5