From a806ac61e8f7f719dc41fa198a0cec01d9a2db0c Mon Sep 17 00:00:00 2001 From: rzmk Date: Sat, 10 Jul 2021 16:38:00 -0400 Subject: [PATCH] Created a number guessing game! --- Day 12/art.py | 10 ++++++++++ Day 12/main.py | 28 ++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+) create mode 100644 Day 12/art.py create mode 100644 Day 12/main.py diff --git a/Day 12/art.py b/Day 12/art.py new file mode 100644 index 0000000..48846eb --- /dev/null +++ b/Day 12/art.py @@ -0,0 +1,10 @@ +logo = """ + _____ _____ _ _ _ _ _ +| __ \ |_ _| | | \ | | | | | | +| | \/_ _ ___ ___ ___ | | | |__ ___ | \| |_ _ _ __ ___ | |__ ___ _ __| | +| | __| | | |/ _ \/ __/ __| | | | '_ \ / _ \ | . ` | | | | '_ ` _ \| '_ \ / _ \ '__| | +| |_\ \ |_| | __/\__ \__ \ | | | | | | __/ | |\ | |_| | | | | | | |_) | __/ | |_| + \____/\__,_|\___||___/___/ \_/ |_| |_|\___| \_| \_/\__,_|_| |_| |_|_.__/ \___|_| (_) + + +""" \ No newline at end of file diff --git a/Day 12/main.py b/Day 12/main.py new file mode 100644 index 0000000..538af9c --- /dev/null +++ b/Day 12/main.py @@ -0,0 +1,28 @@ +from random import randint +from art import logo + +print(logo) +print("Welcome to the Number Guessing Game!") +print("I'm thinking of a number between 1 and 100.") +actual_answer = randint(1, 100) +difficulty = input("Choose a difficulty. Type 'easy' or 'hard': ") +if difficulty == "easy": + guesses = 10 +elif difficulty == "hard": + guesses = 5 + +while guesses > 0: + print(f"You have {guesses} attempts remaining to guess the number.") + answer = input("Make a guess: ") + if int(answer) < actual_answer: + print("Too low.\nGuess again.") + elif int(answer) > actual_answer: + print("Too high.\nGuess again.") + elif int(answer) == actual_answer: + break + guesses -= 1 + +if int(answer) == actual_answer: + print(f"You got it! The answer was {actual_answer}.") +else: + print("You've run out of guesses. You lose.") \ No newline at end of file