IEEE Format Python Exam Document
Part - A Question
8. Design a Bank Account System with Multiple Account Types
Scenario:
You are developing a banking application. The system needs to support multiple types of
bank accounts, such as savings and checking accounts. Both account types share common
functionalities like deposit and withdrawal, but they may have different rules or restrictions
for withdrawals.
Question:
Design an object-oriented system to model the bank accounts:
• Create a parent class BankAccount that includes attributes like account holder’s name,
balance, and account number, as well as methods like deposit() and withdraw().
• Create subclasses SavingsAccount and CheckingAccount that inherit from BankAccount.
The SavingsAccount should have a restriction on the number of withdrawals per month,
while the CheckingAccount should have a lower interest rate.
• Override the withdraw() method in the subclasses to implement specific withdrawal rules.
• Implement a method get_balance() to return the account balance and display it.
• Provide a method to calculate interest in SavingsAccount.
Python Code:
class BankAccount:
def __init__(self, name, balance, account_number):
self.name = name
self.balance = balance
self.account_number = account_number
def deposit(self, amount):
self.balance += amount
print(f"{amount} deposited. New balance: {self.balance}")
def withdraw(self, amount):
if amount <= self.balance:
self.balance -= amount
print(f"{amount} withdrawn. New balance: {self.balance}")
else:
print("Insufficient balance!")
Output Screenshot:
Part - B Question
3. a) What is class and object? (2M)
A class is a blueprint for creating objects in programming. An object is an instance of a class
containing data and behavior defined by the class.
b) Difference between inheritance and polymorphism.
Inheritance allows a class to inherit properties and methods from another class.
Polymorphism allows methods to do different things based on the object calling them.
c) Creating a class and object with class and instance attributes.
class Student:
school = "VFSTR" # Class attribute
def __init__(self, name, roll_no):
self.name = name # Instance attribute
self.roll_no = roll_no
# Creating object
s1 = Student("Ram", 101)
print(s1.name)
print(Student.school)