Saanp pt.4
Saanp pt.4
14
Q1.
class PrintData:
def display(self, n=None, c=None):
if isinstance(n, int) and isinstance(c, str):
print(f"Integer: {n}, Character: {c}")
elif isinstance(n, str) and isinstance(c, int):
print(f"Character: {n}, Integer: {c}")
else:
print("Invalid input")
# Example Usage
obj = PrintData()
obj.display(10, 'A') # Integer first, then Character
obj.display('B', 20) # Character first, then Integer
Output :
Q2.
class Shape:
if breadth is None:
else:
shape = Shape()
Output:
Q3.
class Degree:
def getDegree(self):
print("I got a degree")
class Undergraduate(Degree):
def getDegree(self):
print("I am an Undergraduate")
class Postgraduate(Degree):
def getDegree(self):
print("I am a Postgraduate")
# Example Usage
degree = Degree()
undergrad = Undergraduate()
postgrad = Postgraduate()
degree.getDegree()
undergrad.getDegree()
postgrad.getDegree()
Output :
Practical No.15
Q1.
Output :
class Employee:
self.name = name
self.department = department
self.salary = salary
def display_info(self):
print(f"Department: {self.department}")
print(f"Salary: {self.salary}")
# Example Usage
emp1.display_info()
Output :
Q2.
class Person:
def __init__(self, name, age):
self.name = name
self.age = age
def display(self):
print(f"Name: {self.name}")
print(f"Age: {self.age}")
class Student(Person):
def __init__(self, name, age, student_id, course):
super().__init__(name, age)
self.student_id = student_id
self.course = course
def display(self):
super().display()
print(f"Student ID: {self.student_id}")
print(f"Course: {self.course}")
# Example Usage
student1 = Student("Tanay", 18, "1505", "Computer Engineering")
student1.display()
Output :
Q3.
class Parent1:
def feature1(self):
print("Feature 1 from Parent 1")
class Parent2:
def feature2(self):
print("Feature 2 from Parent 2")
# Example Usage
child_obj = Child()
child_obj.feature1() # Inherited from Parent1
child_obj.feature2() # Inherited from Parent2
child_obj.feature3() # Child's own method
Output :
Practical No.16
Q1.
try:
result = a / b
print(f"Result: {result}")
except ZeroDivisionError:
# Example Usage
divide_numbers(num1, num2)
Output :
Q2.
class InvalidPasswordError(Exception):
pass
def check_password(user_input):
else:
print("Login Successful!")
# Example Usage
try:
check_password(user_password)
except InvalidPasswordError as e:
print(e)
Output :