Moui's K-Notes
A knowledge notes powered by Vuepress
Guess Number Game
# Guess Number
import random
logo = """
__ __ __ __
_____ ____ _ / /_____ __ __ / /____ _ / /_ ___ ____ __ __ ____ ___ / /_ ___ _____
/ ___// __ `// // ___// / / // // __ `// __// _ \ / __ \ / / / // __ `__ \ / __ \ / _ \ / ___/
/ /__ / /_/ // // /__ / /_/ // // /_/ // /_ / __/ / / / // /_/ // / / / / // /_/ // __// /
\___/ \__,_//_/ \___/ \__,_//_/ \__,_/ \__/ \___/ /_/ /_/ \__,_//_/ /_/ /_//_.___/ \___//_/
"""
# random.randint(1,100)
guess_number = random.choice(range(0, 101))
easy_try_time = 10
hard_try_time = 5
def play_game():
print(logo)
print("Welcome to the Number Guessing Game!")
print("I'm thinking of a number between 1 and 100.")
# print(f"Pssst, the correct answer is {guess_number}")
type = input("Choose a difficulty. Type 'easy' or 'hard'")
try_nums = 0
if type == "easy":
try_nums = easy_try_time
else:
try_nums = hard_try_time
end_game = False
while not end_game:
print(f"You have {try_nums} attempts remaining to guess the number.")
num = int(input("Make a guess:"))
if num == guess_number:
print(f"You got it! The answer was {num}.")
end_game = True
elif num < guess_number:
print("Too low.")
else:
print("Too High.")
try_nums -= 1
if try_nums > 0:
print("Guess again.")
else:
print(f"You've run out of guesses, you lose, the answer is {guess_number}")
end_game = True
play_game()