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
What is an f string in python?
what is the statement that can be used in python if the program requires no action but requires a statement syntactically?
How do I sleep in python?
Where do we use python scripting?
What is range() in python? Give an example to explain it.
How can you declare multiple assignments in one statement?
Explain me five benefits of using python?
Which is the default function in a class?
What does input () do in python?
Is coding useful in finance?
What is %s %d in python?
Why do we use raw_input in python?
Write program to validate the email address in python?
Is c++ or python better?
Explain about the programming language python?