Created a number guessing game!
This commit is contained in:
parent
8655f3fa8e
commit
a806ac61e8
2 changed files with 38 additions and 0 deletions
10
Day 12/art.py
Normal file
10
Day 12/art.py
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
logo = """
|
||||
_____ _____ _ _ _ _ _
|
||||
| __ \ |_ _| | | \ | | | | | |
|
||||
| | \/_ _ ___ ___ ___ | | | |__ ___ | \| |_ _ _ __ ___ | |__ ___ _ __| |
|
||||
| | __| | | |/ _ \/ __/ __| | | | '_ \ / _ \ | . ` | | | | '_ ` _ \| '_ \ / _ \ '__| |
|
||||
| |_\ \ |_| | __/\__ \__ \ | | | | | | __/ | |\ | |_| | | | | | | |_) | __/ | |_|
|
||||
\____/\__,_|\___||___/___/ \_/ |_| |_|\___| \_| \_/\__,_|_| |_| |_|_.__/ \___|_| (_)
|
||||
|
||||
|
||||
"""
|
||||
28
Day 12/main.py
Normal file
28
Day 12/main.py
Normal file
|
|
@ -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.")
|
||||
Loading…
Add table
Add a link
Reference in a new issue