-
Notifications
You must be signed in to change notification settings - Fork 4k
Expand file tree
/
Copy pathLuke_Hong_game.py
More file actions
33 lines (25 loc) · 778 Bytes
/
Luke_Hong_game.py
File metadata and controls
33 lines (25 loc) · 778 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import random
print("Welcome to the Number Guessing Game!")
print("I'm thinking of a number between 1 and 100.")
# generate a random number
secret_number = random.randint(1, 100)
# keep track of attempts
attempts = 0
while True:
guess = input("Take a guess (or type 'quit' to stop): ")
if guess.lower() == "quit":
print("Goodbye!")
break
if not guess.isdigit():
print("Please enter a number!")
continue
guess = int(guess)
attempts += 1
if guess < secret_number:
print("Too low! Try again.")
elif guess > secret_number:
print("Too high! Try again.")
else:
print(f"🎉 You got it! The number was {secret_number}.")
print(f"It took you {attempts} tries.")
break