Python Function with Assertion and Exception Handling | VTU Q7 | 1BPLC105B
Автор: Abdul Muqeet
Загружено: 2026-01-08
Просмотров: 41
Python Program Using Function, Assertion, and Exception Handling
VTU Model Question Paper – 1BPLC105B (Question 7)
In this video, I solve a Python programming question from the VTU Model Question Paper for the subject 1BPLC105B.
Question (7):
Develop a function named DivExp which takes two parameters a and b, and returns c = a / b. Write a suitable assertion for a greater than 0 in the function and raise an exception when b = 0. Develop a suitable program that reads two console values and calls the function DivExp.
PYTHON SOLUTION USED
def divexp(a, b):
assert a greaterthan 0, "a must be greater than 0"
if b == 0:
raise ZeroDivisionError("b cant be 0")
return a / b
try:
print("Result =", divexp(float(input("a: ")), float(input("b: "))))
except Exception as e:
print("Error:", e)
CONCEPTS COVERED
Functions in Python
Assertions
Exception handling using try-except
Raising exceptions
ZeroDivisionError
User input handling
This video is useful for
VTU students
First year engineering students
Python beginners
Exam and viva preparation
Like, Share, and Subscribe for more VTU Python programming lab solutions and exam-oriented tutorials.
Доступные форматы для скачивания:
Скачать видео mp4
-
Информация по загрузке: