Guess the Number Game

PHOTO EMBED

Sat Sep 03 2022 10:39:09 GMT+0000 (Coordinated Universal Time)

Saved by @yusufalao #python #guess_the_number

import random
#from art import logo

logo = """
   _____                       _   _            _   _                 _                  
  / ____|                     | | | |          | \ | |               | |                 
 | |  __ _   _  ___  ___ ___  | |_| |__   ___  |  \| |_   _ _ __ ___ | |__   ___ _ __    
 | | |_ | | | |/ _ \/ __/ __| | __| '_ \ / _ \ | . ` | | | | '_ ` _ \| '_ \ / _ \ '__|   
 | |__| | |_| |  __/\__ \__ \ | |_| | | |  __/ | |\  | |_| | | | | | | |_) |  __/ |_ _ _ 
  \_____|\__,_|\___||___/___/  \__|_| |_|\___| |_| \_|\__,_|_| |_| |_|_.__/ \___|_(_|_|_)
                                                                                         
                                                                                       
"""
end_game = False
while not end_game:
    #print(logo)
    print("Welcome to the Number Guessing Game!")

    print("I'm thnking of a number between 1 and 100.")

    the_number = random.randint(1,100)
    difficulty = ""

    print(f"Hint: \"Shhhh... the number is {the_number}\"\n\n")

    def wrong_guess(num):
        if num:
            print(f"Guess again.\nYou have {num} attempts remaining to guess the number.\n")
        else:
            print(f"You've run out of guesses.\nThe correct number was {the_number}, you lose.")

    choices = ["e","easy","h","hard"]
    chances = 3
    while difficulty not in choices and chances:

        difficulty = input("Choose a difficulty. Type 'easy' or hard': ").lower()
        chances -= 1

    if not chances:
        print("Game Over. No valid difficulty entered.")
    else:
        print(difficulty)

        if difficulty.startswith("h"):
            attempts = 5
        else:
            attempts = 10
        print(f"You have {attempts} attempts remaining to guess the number.")

        guess = 0
        while guess != the_number and attempts:
            guess = int(input("Make a guess: "))
            attempts -= 1
            if guess == the_number:
                print(f"You got it! The answer was {the_number}.")
            else:
                if guess > the_number:
                    print("Too high.")
                else:
                    print("Too low.")
                wrong_guess(attempts)
            
        play_again = input("\nDo you want to play again. Type 'y' or 'n': ")
        if play_again == 'n':
            end_game = True
            print("Goodbye.")
content_copyCOPY