-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.py
More file actions
24 lines (20 loc) · 749 Bytes
/
test.py
File metadata and controls
24 lines (20 loc) · 749 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
def main():
print("Welcome to the Number Guessing Game!")
number_to_guess = random.randint(1, 100)
attempts = 0
while True:
try:
user_guess = int(input("Guess a number between 1 and 100: "))
attempts += 1
if user_guess < number_to_guess:
print("Too low! Try again.")
elif user_guess > number_to_guess:
print("Too high! Try again.")
else:
print(f"Congratulations! You guessed the number {number_to_guess} in {attempts} attempts.")
break
except ValueError:
print("Invalid input. Please enter a number.")
if __name__ == "__ambrose__":
main()