I am trying to create an exception handling into a loop .
I have created the below code and I would like to put an exception in userId1 and userid2.
For example, the total amount of users is 943, so when the user enters an userId which is greater than 943, to put an exception with a message 'Sorry, this userId does not exist' and to start the loop over again.
I tried to do it with the try: and except KeyError: but didn't play correct or I didn't write in appropriate order.
How can I write it?
exit=False
while exit is False:
print("Hello Lady or Gentleman, this is a very primitive movie recommnedation system, please follow the instructions below : ")
print("---------------------------------------------------------------------------")
print("1) If you would like to find the difference 1 please press 1")
print("2) If you would like to find the difference 2 please press 2")
print("3) If you would like to exit, then press 0")
option=False
while option is False:
print("Εnter what would you like to find please :",end=" ")
option=input();
if option =='1':
print("The total number of users is 943, so you should enter 2 user_ids lower than 944")
print('---------------------')
print("Enter the first userId please :",end=" ")
user1 = input();
print("Enter the second userId please :",end=" ")
user2 = input();
elif option == '2':
print("The total number of movies is 1682, so you should enter 2 movie_ids lower than 1683")
print('-------------------')
print("Enter the first bookId please :",end=" ")
bookId1 = input();
print("Enter the second bookId1 please :",end=" ")
bookId2= input();
elif option == '0':
exit = True
print("Thank you very much")
break
else:
option = False
print("This option is not valid, Please try again!")