Ex 09
Ex 09
Exp - 9(a) - To write a Python program that simulates basic banking operations using object-
oriented programming concepts. The program demonstrates the use of instance methods, class
methods, and static methods within a BankAccount class, along with user input handling and
validation.
class BankAccount:
bank_name = "National Bank"
def show_balance(self):
print(self.account_holder + "'s balance: ₹" + str(self.balance))
@classmethod
def change_bank_name(cls, new_name):
cls.bank_name = new_name
print("Bank name changed to: " + cls.bank_name)
@staticmethod
def is_valid_account_number(account_number):
return isinstance(account_number, str) and len(account_number) == 6 and
account_number.isdigit()
account.show_balance()
def display_personal_info(self):
print("Name: " + self.name)
print("Age: " + str(self.age))
def display_employee_info(self):
print("Employee ID: " + self.employee_id)
print("Department: " + self.department)
def display_manager_info(self):
print("Team Size: " + str(self.team_size))
# User input
name = input("Enter manager's name: ")
age = int(input("Enter age: "))
emp_id = input("Enter employee ID: ")
dept = input("Enter department: ")
team_size = int(input("Enter number of team members: "))
# Create Manager object
mgr = Manager(name, age, emp_id, dept, team_size)
Exp - 9(c) - To implement method overriding in Python by creating a base Student class and
derived classes Undergraduate and Postgraduate that override the calculate_marks method to
perform different calculations such as percentage and grade evaluation based on student type.
# Base class
class Student:
def calculate_marks(self, marks):
print("Total marks (base):", sum(marks))
# Main program
marks = [85, 90, 78, 92]
def show_address(self):
print("Address: {}, {}, {}".format(self.city, self.state, self.zipcode))
def show_details(self):
print("Name:", self.name)
print("Age:", self.age)
self.address.show_address() # Delegation to Address object
student.show_details()