-
Notifications
You must be signed in to change notification settings - Fork 0
/
task2.py
32 lines (24 loc) · 985 Bytes
/
task2.py
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
import random
def guess_the_number():
print("Welcome to !Guess the Number Game!")
print("I have selected a number between 1 and 100")
print("Try to guess the number in few attempts as possible")
number_to_guess = random.randint(1, 100)
attempts = 0
while True:
try:
user_guess = int(input("Enter your guess: "))
attempts += 1
if user_guess < number_to_guess:
print("sorry! wrong prediction")
print("CLUE:Higher! the !number")
elif user_guess > number_to_guess:
print("sorry! wrong prediction")
print("CLUE: Lower! the !number")
else:
print(f"Congratulations! You've guessed the number in {attempts} attempts.")
break
except ValueError:
print("Invalid input. Please enter a valid integer.")
if __name__ == "__main__":
guess_the_number()