Consider the code given below and fill in the blanks. print ("Learning Exceptions...") try: num1= int(input ("Enter the first number")) num2=int(input("Enter the second number")) quotient=(num1/num2) print ("Both the numbers entered were correct") except _____: # to enter only integers print ("Please enter only numbers") except _____: # Denominator should not be zero print("Number 2 should not be zero") else: print("Great .. you are a good programmer") _____: # to be executed at the end print("JOB OVER... GO GET SOME REST")
- ValueError
- ZeroDivisionError
- finally
Explanation
The first blank requires 'ValueError' because the code attempts to convert user input into an integer using int(), and Program 1-6 in the context demonstrates that entering a non-integer raises a ValueError. The second blank requires 'ZeroDivisionError' because the code performs division (num1/num2), and Program 1-2 and Program 1-6 show that dividing by zero raises this specific exception. The third blank requires 'finally' because the comment indicates the code must execute at the end; Program 1-6 and Program 1-7 illustrate that the finally clause is executed irrespective of whether an exception is raised or not.
Solution Steps
Step 1: Analyze the first except block. The operation int(input(...)) fails if the input is not a number. Referring to Program 1-6, this raises ValueError.
Step 2: Analyze the second except block. The operation num1/num2 fails if num2 is zero. Referring to Program 1-2, this raises ZeroDivisionError.
Step 3: Analyze the final blank. The comment 'to be executed at the end' implies a cleanup action. Referring to Program 1-6, the finally clause is used for code that executes at the end regardless of exceptions.