This my code. I tried clear() and os.system('cls') and Ipython function , but they didn't work. What else to clear output on the console to get newest input data? Is anything wrong in my code? But I didn't recognize error in my code.
from random import randint
import os
def play_the_game():
guess_number()
if input("Do you want to play again? Type 'y' or 'n': ") == "y":
os.system('cls')
play_the_game()
else:
print("Bye.")
def guess_number():
print("Welcome to the Number Guessing Game!\nI'm thinking a number between 1 and 100.")
level = input("Choose a difficulty. Type 'easy' or 'hard': ").lower()
if level == "hard":
print("You have 5 attempts remaining to guess the number.")
guess = int(input("Make a guess: "))
life = 5
else:
print("You have 10 attempts remaining to guess the number.")
guess = int(input("Make a guess: "))
life = 10
number = randint(0, 100)
while life > 0:
if guess > 100 or guess < 0:
guess = int(input("Please enter a number between 0 and 100. Try again: "))
if guess > number:
life -= 1
print(f"Too high.\nGuess again.")
if life == 0:
print("You've run out of guesses. You lose.")
else:
print(f"You have {life} attempts remaining to guess the number.")
guess = int(input("Make a guess: "))
elif guess < number:
life -= 1
print(f"Too low.\nGuess again.")
if life == 0:
print("You've run out of guesses. You lose.")
else:
print(f"You have {life} attempts remaining to guess the number.")
guess = int(input("Make a guess: "))
else:
print(f"You got it! The answer is {guess}.")
life = 0
play_the_game()