ValueError Exception in Python with Example
belongs to collection: Python Exception Handling Programs
All Answers
total answers (1)
Severity: 8192
Message: str_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated
Filename: libraries/Filtered_db.php
Line Number: 23
belongs to collection: Python Exception Handling Programs
total answers (1)
Program to illustrate ValueError in Python
Output:
Explanation:
In the above code, we have created two variables num1 and num2 and taken user input for their values. Both the values entered need to be integer values only. And then we have printed their sum. The exception we have handled here is valueError but we have not put any upper limit to the value of the integer to be entered, and by default you can create an integer as big as you want in python. And hence, if we enter a non-integer value the ValueError exception returns the exception statement.
Example 2:
Output:
need an explanation for this answer? contact us directly to get an explanation for this answer