I have a dictionary with certain items. I want to accept the key input from the user and display the corresponding item. However if the user enters the wrong key which is not defined in the dictionary, it throws key error exception.
I want the code to go back to the line end execute from where the command for user input is written if key error exception occurs.
I have used try except statements but shows an error. Please help me to fix this.
Below is my code:
a={'name':'pav','q1':'y','age':26}
try:
k=input()
print (a[k])
except KeyError:
continue
whileorfor) loop tocontinue. Are you? What exception, exactly?