Untitled

mail@pastecode.io avatar
unknown
python
2 years ago
1.3 kB
3
Indexable
Never
from art import logo
import random

def game():
    print(logo)
    print('Welcome to the Number Guessing Game!\nI\'m thinking of a number between 1 and 100.')

    attempts_number = int
    difficulty_level = input("Choose a difficulty. Type 'easy' or 'hard': ")

    if difficulty_level == 'easy':
        attempts_number = 10
    elif difficulty_level == 'hard':
        attempts_number = 5

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

    number_to_guess = random.randint(1, 100)
    # print(number_to_guess)

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

    while number_to_guess != guess and attempts_number > 1:

        if number_to_guess < guess:
            attempts_number -= 1
            print(f"Too high.\nYou have {attempts_number} attempts to guess a number")
            guess = int(input("Guess again: "))

        elif number_to_guess > guess:
            attempts_number -= 1
            print(f"Too low!\nYou have {attempts_number} attempts to guess a number")
            guess = int(input("Guess again: "))

    if number_to_guess == guess:
        print(f"You got it! The answer was {number_to_guess}.")
    else:
        print(f"You've run out of guesses, you lose. The number was {number_to_guess}.")

game()