random game easier ver

Run Settings
LanguagePython
Language Version
Run Command
import random def number_guessing_game(): secret number = random.randint(1,100) attempts = 0 max_attempts = 5 print ("Welcome to Guessing Game") print (f"Think of a number between 1 to 100. You have {max_attempts}attempts.") while attempts < max_attempts: try: guess = int(input("Enter your guess: ")) attempts +=1 if guess == secret_number: print(f"Congrats! You guessed the number in {attempts}attempts!") return elif guess < secret number: print ("Oops too low. Please try again") else: print ("Oops too high. Please try again") print(f"attempts remaining: {max_attempts - attempts}") except ValueError: print ("Please enter a valid number") continue print(f"Game Over! The number was {secret number}")
Editor Settings
Theme
Key bindings
Full width
Lines