-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
24 lines (18 loc) · 688 Bytes
/
app.py
File metadata and controls
24 lines (18 loc) · 688 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
import random
print("Welcome to the Number Guessing Game!")
print("I'm thinking of a number between 1 and 100.")
print("You have 5 chances to guess it right.")
secret_number = random.randint(1, 100)
guess_count = 0
while guess_count < 5:
guess = int(input("Guess the number: "))
guess_count += 1
if guess < secret_number:
print("Too low. Guess again.")
elif guess > secret_number:
print("Too high. Guess again.")
else:
print(f"Congratulations! You guessed it right in {guess_count} tries.")
break
if guess_count == 5:
print(f"Sorry, you couldn't guess the number. The number was {secret_number}.")