SlideShare a Scribd company logo
TRICKY QUESTIONS BASED ON
EXCEPTIONAL HANDLING
Vinay Agrawal
Asst. Professor
CSE Dept.
SHARDA University,
AGRA
1. Which number is not printed by this code?
try:
print(100)
print(5/0)
print(200)
except ZeroDivisionError:
print(300)
finally:
print(400)
ANS. 200
2. What will be the output of the following program?
try:
fp=open("a.txt","r")
try:
fp.write("This is my test file")
finally:
print("Closing the file")
fp.close()
except IOError as e:
print("Error:",e)
ANS. Closing the file
Error:not writable
3. What will be the output of the following program?
l=['a',0,2]
for i in l:
try:
print(i)
r=1/int(i)
break
except:
print("Error")
ANS. a
Error
0
Error
2
4. What will be the output of the following program?
while 1:
try:
n=int(input(“Enter the integer”))
break
except ValueError:
print(“Enter again’)
else:
print(“Congratulations…Number accepted”)
ANS. If number is entered, it will come out from the loop and nothing will be
printed. If non-integer number is entered, then Enter again will be printed
and ask again the input
5. What will be the output of the following program?
def func1(i):
return i/0
def func2():
raise Exception("Raising Exception")
def func3():
try:
func1(5)
except Exception as e:
print(e)
#raise
try:
func2()
except Exception as e:
print(e)
func3()
ANS. division by zero
Raising Exception

More Related Content

PPTX
Exceptional Handling in the python .pptx
PPTX
Python Exceptions Powerpoint Presentation
PDF
Python programming : Exceptions
PDF
Exception handling in python
PDF
lecs101.pdfgggggggggggggggggggddddddddddddb
PPTX
Python Exception handling using Try-Except-Finally
PPTX
Chapter 13 exceptional handling
PDF
Python Programming - X. Exception Handling and Assertions
Exceptional Handling in the python .pptx
Python Exceptions Powerpoint Presentation
Python programming : Exceptions
Exception handling in python
lecs101.pdfgggggggggggggggggggddddddddddddb
Python Exception handling using Try-Except-Finally
Chapter 13 exceptional handling
Python Programming - X. Exception Handling and Assertions

Similar to 11Exceptional Handling In Python Language.pptx (20)

PPTX
Exception Handling.pptx
PPTX
Exception handling.pptxnn h
PPTX
Exception Handling in Python Programming.pptx
PPTX
Exception Handling in Python programming.pptx
PPTX
Exception Handling in python programming.pptx
PDF
Exception-Handling Exception-HandlingFpptx.pdf
PPTX
Error and exception in python
PPTX
Exception handling with python class 12.pptx
PPTX
exception handling.pptx
PPTX
Python Programming Essentials - M21 - Exception Handling
PPTX
Exception Handling in Python topic .pptx
PPTX
Python Exception Handling
PDF
Exception Handling In Python | Exceptions In Python | Python Programming Tuto...
PPTX
Download Wondershare Filmora Crack Latest 2025
PPTX
Adobe Photoshop 2025 Cracked Latest Version
PPTX
FL Studio Producer Edition Crack 24 + Latest Version [2025]
PDF
Lecture 12 exceptions
PPTX
Exception Handling in Python
PPTX
Exception handling.pptx
Exception Handling.pptx
Exception handling.pptxnn h
Exception Handling in Python Programming.pptx
Exception Handling in Python programming.pptx
Exception Handling in python programming.pptx
Exception-Handling Exception-HandlingFpptx.pdf
Error and exception in python
Exception handling with python class 12.pptx
exception handling.pptx
Python Programming Essentials - M21 - Exception Handling
Exception Handling in Python topic .pptx
Python Exception Handling
Exception Handling In Python | Exceptions In Python | Python Programming Tuto...
Download Wondershare Filmora Crack Latest 2025
Adobe Photoshop 2025 Cracked Latest Version
FL Studio Producer Edition Crack 24 + Latest Version [2025]
Lecture 12 exceptions
Exception Handling in Python
Exception handling.pptx
Ad

Recently uploaded (20)

PDF
BIO-INSPIRED HORMONAL MODULATION AND ADAPTIVE ORCHESTRATION IN S-AI-GPT
PPTX
Fundamentals of Mechanical Engineering.pptx
PDF
SMART SIGNAL TIMING FOR URBAN INTERSECTIONS USING REAL-TIME VEHICLE DETECTI...
PDF
Artificial Superintelligence (ASI) Alliance Vision Paper.pdf
PPTX
Feature types and data preprocessing steps
PPTX
"Array and Linked List in Data Structures with Types, Operations, Implementat...
PPT
Total quality management ppt for engineering students
PDF
Accra-Kumasi Expressway - Prefeasibility Report Volume 1 of 7.11.2018.pdf
PPTX
Fundamentals of safety and accident prevention -final (1).pptx
PDF
distributed database system" (DDBS) is often used to refer to both the distri...
PDF
R24 SURVEYING LAB MANUAL for civil enggi
PDF
Design Guidelines and solutions for Plastics parts
PDF
Human-AI Collaboration: Balancing Agentic AI and Autonomy in Hybrid Systems
PDF
Influence of Green Infrastructure on Residents’ Endorsement of the New Ecolog...
PDF
22EC502-MICROCONTROLLER AND INTERFACING-8051 MICROCONTROLLER.pdf
PPTX
Nature of X-rays, X- Ray Equipment, Fluoroscopy
PDF
PREDICTION OF DIABETES FROM ELECTRONIC HEALTH RECORDS
PDF
Level 2 – IBM Data and AI Fundamentals (1)_v1.1.PDF
PDF
Abrasive, erosive and cavitation wear.pdf
PDF
A SYSTEMATIC REVIEW OF APPLICATIONS IN FRAUD DETECTION
BIO-INSPIRED HORMONAL MODULATION AND ADAPTIVE ORCHESTRATION IN S-AI-GPT
Fundamentals of Mechanical Engineering.pptx
SMART SIGNAL TIMING FOR URBAN INTERSECTIONS USING REAL-TIME VEHICLE DETECTI...
Artificial Superintelligence (ASI) Alliance Vision Paper.pdf
Feature types and data preprocessing steps
"Array and Linked List in Data Structures with Types, Operations, Implementat...
Total quality management ppt for engineering students
Accra-Kumasi Expressway - Prefeasibility Report Volume 1 of 7.11.2018.pdf
Fundamentals of safety and accident prevention -final (1).pptx
distributed database system" (DDBS) is often used to refer to both the distri...
R24 SURVEYING LAB MANUAL for civil enggi
Design Guidelines and solutions for Plastics parts
Human-AI Collaboration: Balancing Agentic AI and Autonomy in Hybrid Systems
Influence of Green Infrastructure on Residents’ Endorsement of the New Ecolog...
22EC502-MICROCONTROLLER AND INTERFACING-8051 MICROCONTROLLER.pdf
Nature of X-rays, X- Ray Equipment, Fluoroscopy
PREDICTION OF DIABETES FROM ELECTRONIC HEALTH RECORDS
Level 2 – IBM Data and AI Fundamentals (1)_v1.1.PDF
Abrasive, erosive and cavitation wear.pdf
A SYSTEMATIC REVIEW OF APPLICATIONS IN FRAUD DETECTION
Ad

11Exceptional Handling In Python Language.pptx

  • 1. TRICKY QUESTIONS BASED ON EXCEPTIONAL HANDLING Vinay Agrawal Asst. Professor CSE Dept. SHARDA University, AGRA
  • 2. 1. Which number is not printed by this code? try: print(100) print(5/0) print(200) except ZeroDivisionError: print(300) finally: print(400) ANS. 200
  • 3. 2. What will be the output of the following program? try: fp=open("a.txt","r") try: fp.write("This is my test file") finally: print("Closing the file") fp.close() except IOError as e: print("Error:",e) ANS. Closing the file Error:not writable
  • 4. 3. What will be the output of the following program? l=['a',0,2] for i in l: try: print(i) r=1/int(i) break except: print("Error") ANS. a Error 0 Error 2
  • 5. 4. What will be the output of the following program? while 1: try: n=int(input(“Enter the integer”)) break except ValueError: print(“Enter again’) else: print(“Congratulations…Number accepted”) ANS. If number is entered, it will come out from the loop and nothing will be printed. If non-integer number is entered, then Enter again will be printed and ask again the input
  • 6. 5. What will be the output of the following program? def func1(i): return i/0 def func2(): raise Exception("Raising Exception") def func3(): try: func1(5) except Exception as e: print(e) #raise try: func2() except Exception as e: print(e) func3() ANS. division by zero Raising Exception