Untitled
unknown
plain_text
2 years ago
663 B
4
Indexable
import random print("Welcome to Guess the Number game!") # generate a random number between 1 and 100 secret_number = random.randint(1, 100) # initialize the number of tries to 0 tries = 0 while True: # ask the player to guess the number guess = int(input("Guess the number (between 1 and 100): ")) # increment the number of tries tries += 1 # provide feedback on the guess if guess < secret_number: print("Too low!") elif guess > secret_number: print("Too high!") else: # the player guessed the correct number print(f"Congratulations! You guessed the number in {tries} tries.") break
Editor is loading...