-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1.py
More file actions
27 lines (21 loc) · 769 Bytes
/
1.py
File metadata and controls
27 lines (21 loc) · 769 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
import random
# Generate a random number between 1 and 100
secret_number = random.randint(1, 100)
attempts = 0
print("Welcome to the Number Guessing Game!")
print("I'm thinking of a number between 1 and 100.")
while True:
try:
# Get player's guess
guess = int(input("Enter your guess: "))
attempts += 1
# Check if guess is correct
if guess == secret_number:
print(f"Congratulations! You found the number in {attempts} attempts!")
break
elif guess < secret_number:
print("Too low! Try again.")
else:
print("Too high! Try again.")
except ValueError:
print(" its not valid! Please enter a valid number!")