Share your repls and programming experiences

← Back to all posts
##### my guess the number game code- lesson 12

from art import logo
import random

print(logo)

print("Welcome to the Numbers Guessing Game! ")
print("I'm thinking of a number between 1 and 100")
number= random.randint(0,100)
def level():
difficulty = input("Choose a difficulty. Type 'easy' or 'hard': ")
if difficulty == "easy":
maximum_attempts = 10
else:
maximum_attempts= 5

return maximum_attempts

def has_tries_left():

if attempts_left > 0:
print("Guess again.")
print(f"You have {attempts_left} attempts remaining to guess the number.")
elif attempts_left == 0:
print(f"You've run out of guesses, you lose. The answer was {number}")

attempts_left = level()
guess=""

print(f"You have {attempts_left} attempts remaining to guess the number")

while guess != number and attempts_left > 0:

guess = int(input("Make a guess: "))

if guess > number:
attempts_left -= 1
print("Too high.")
has_tries_left()

elif guess < number:
attempts_left -= 1
print("Too low.")
has_tries_left()

else:
print(f"You got it! The answer was {number}.")