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
How many name spaces are defined in python?
How to exit python script in command prompt?
What packages in the standard library, useful for data science work, do you know?
What is tuple in python?
Explain about indexing and slicing operation in sequences?
What is a list in python?
How to retrieve data from a table in mysql database through python code?
Does python support database programming?
What is the scipy?
How do you call functions in python?
Is list iterable in python?
What is python used for at google?
How many items are in a list python?
What are its benefits of flask?
What type of a language is python? Interpreted or Compiled?