Answer Posted / chaitanya
Errors detected during execution of program are called exceptions. Exceptions can be handled using the try..except statement. We basically put our usual statements within the try-block and put all our error handlers in the except-block.
try…except demo code:
>>> while True:
try:
x = int(raw_input("Enter no. of your choice: "))
break
except ValueError:
print "Oops! Not a valid number. Attempt again"
Enter no. of your choice: 12ww
Oops! Not a valid number. Attempt again
Enter no. of your choice: hi there
Oops! Not a valid number. Attempt again
Enter no. of your choice: 22
>>>
| Is This Answer Correct ? | 0 Yes | 0 No |
Post New Answer View All Answers
Which server is best for python?
How can I learn python for free?
Explain the use of the ‘nonlocal’ keyword in python?
Which methods/functions do we use to determine the type of instance and inheritance?
What is python db api?
What does len() do?
How does ternary operator work in python?
How do you define a function in python 3?
What are the basic elements of python?
Explain how to delete a file in Python?
When does dictionary is used instead of a list in python?
Is python call by reference or value?
How does determine the python manage the memory?
List out atleast two loop control statements?
What is numpy array in python?