0

Can anyone help me with this code, Exception handling does not seem to work.. Also open to improvements

#Guessing Game in python import random n1=int(input("Please enter the lower range: ")) n2=int(input("Please enter the higher range: ")) try: if(n1>n2): print("First number in a range should be lower than the second value. Please enter again: ") except ValueError: print("First number in a range should be lower than the second value. Please enter again: ") my_num= random.randint(n1,n2) count=0 while(count<3): a=int(input("Please enter your guess: ")) count=count +1 if(a<my_num): print("Please go higher, the number is between ",n1,n2) elif(a>my_num): print("Please go lower, the number is between ", n1,n2) else: break; if a==my_num: print("You are on point!!!") else: print("Sorry, the number was ", my_num)

7th Jun 2021, 3:57 AM
Niloy Chatterjee
1 Antwort
0
Use if, else. I think an error only happens if the values n1 and n2 can't be compared.
7th Jun 2021, 4:24 AM
Paul
Paul - avatar