Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
998 B
1
Indexable
Never
import random

# Set the range of numbers for the game
min_num = 1
max_num = 20

# Generate a random number for the player to guess
secret_num = random.randint(min_num, max_num)

# Give the player 5 guesses to find the secret number
num_guesses = 5

# Start the game loop
while num_guesses > 0:
    # Ask the player to guess a number
    guess = int(input("Guess a number between {} and {}: ".format(min_num, max_num)))
    
    # Decrement the number of guesses
    num_guesses -= 1
    
    # Check if the player's guess is correct
    if guess == secret_num:
        print("Congratulations! You guessed the secret number!")
        break
    elif guess < secret_num:
        print("Too low! You have {} guesses left.".format(num_guesses))
    else:
        print("Too high! You have {} guesses left.".format(num_guesses))

# If the player runs out of guesses, reveal the secret number
if num_guesses == 0:
    print("Sorry, you ran out of guesses. The secret number was {}.".format(secret_num))