Python program
Python program
print("Matrix A:\n", A)
print("Matrix B:\n", B)
# Matrix Addition
print("\nMatrix Addition:\n", A + B)
# Matrix Subtraction
print("\nMatrix Subtraction:\n", A - B)
# Element-wise Multiplication
print("\nElement-wise Multiplication:\n", A * B)
# Element-wise Division
print("\nElement-wise Division:\n", A / B)
# Concatenating strings
3.import numpy as np
else:
print("Invalid input!")
# Creating object
obj = PrintValue()
class Shape:
# Creating object
shape = Shape()
# Calculating areas
class Degree:
def getDegree(self):
class Undergraduate(Degree):
def getDegree(self):
print("I am an Undergraduate")
class Postgraduate(Degree):
def getDegree(self):
print("I am a Postgraduate")
deg = Degree()
ug = Undergraduate()
pg = Postgraduate()
pg.getDegree()
7
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}")
print("\nEmployee Information:")
emp.display_info()
class Person:
self.name = name
self.age = age
def display_person(self):
print(f"Name: {self.name}")
print(f"Age: {self.age}")
class Student(Person): # Inheriting from Person
super().__init__(name, age)
self.roll_no = roll_no
self.course = course
def display_student(self):
self.display_person()
print(f"Course: {self.course}")
print("\nStudent Information:")
stud.display_student()
class Teacher:
self.subject = subject
def display_subject(self):
print(f"Teaches: {self.subject}")
class Researcher:
def display_research(self):
# Multiple Inheritance
Teacher.__init__(self, subject)
Researcher.__init__(self, research_topic)
self.name = name
def display_info(self):
self.display_subject()
self.display_research()
print("\nProfessor Information:")
prof.display_info()
1. Check for ZeroDivisionError Exception
try:
print(f"Result: {result}")
except ZeroDivisionError:
except ValueError:
Example Output:
Enter numerator: 10
Enter denominator: 0
class PasswordError(Exception):
self.message = message
super().__init__(self.message)
def check_password(password):
if len(password) < 6:
raise PasswordError
else:
print("Password is valid.")
try:
check_password(user_password)
except PasswordError as e:
print(e)
Example Output:
Password is valid.