Wa0006
Wa0006
2203051240115
SET-2
PRACTICAL-1
AIM : A program that models a bank account, with classes for
the account, the customer, and the bank
Problem Statement:
Create a program that models a bank account system. The system should consist of classes
representing the bank account, the customer, and the bank itself.
Program Description:
The program will simulate basic banking operations such as creating a new account, depositing
and withdrawing money, checking the account balance, and managing customer information. It
will use object-oriented programming principles with classes to organize and structure the data
and behavior.
Algorithm:
1. Define a Customer class with attributes like customer ID, name, address, and contact details.
2. Create a BankAccount class with attributes such as account number, account holder (linked to a
Customer), balance, and account type (e.g., savings or checking).
3. Implement methods in the BankAccount class for deposit, withdrawal, and checking the account
balance.
4. Develop a Bank class to manage a collection of accounts, allowing the creation of new accounts,
retrieval of account details, and overall management of the bank.
Source Code:
import random
class Customer:
self.name = name
self.address = address
self.contact_number = contact_number
self.accounts = []
BIDISHA BISWAS
2203051240115
def create_account(self, account_type, initial_balance):
account_number = Bank.generate_account_number()
self.accounts.append(account)
return account
def display_customer_info(self):
print(f"Address: {self.address}")
print("Accounts:")
print(f" - {account}")
class BankAccount:
self.account_type = account_type
self.balance = balance
self.owner = owner
self.account_number = account_number
self.balance += amount
self.balance -= amount
else:
print("Insufficient funds!")
class Bank:
self.name = name
self.customers = []
self.customers.append(customer)
@staticmethod
def generate_account_number():
def display_bank_info(self):
print("Customers:")
customer.display_customer_info()
3
BIDISHA BISWAS
2203051240115
print()
if account.account_number == account_number:
return account
return None
# Example usage
# Create a bank
customer_list=[]
while True:
try:
choice = int(input())
if choice==1:
# Create a customer
customer_list.append(customer_obj)
4
BIDISHA BISWAS
2203051240115
my_bank.add_customer(customer_obj)
while True:
if acc_type == 1:
break
elif acc_type == 2:
break
elif acc_type == 3:
break
else:
if choice==2:
account_to_transact = my_bank.find_account_by_number(account_number_input)
if account_to_transact:
print(f"\nWelcome, {account_to_transact.owner.name}!")
print(account_to_transact)
while True:
5
BIDISHA BISWAS
2203051240115
print("1. Enter 1 to deposit\n2. Enter 2 to Withdrawl\n3. Enter 3 to Check the Balance\n4. Exit")
if option==1:
# Deposit
account_to_transact.deposit(deposit_amount)
elif option==2:
# Withdrawal
account_to_transact.withdraw(withdrawal_amount)
elif option==3:
print(account_to_transact)
elif option==4:
break
else:
print("Invalid Option")
else:
if choice==3:
my_bank.display_bank_info()
elif choice==4:
break
6
BIDISHA BISWAS
2203051240115
else:
pass
except ValueError:
continue
Class Diagram:
7
BIDISHA BISWAS
2203051240115
Expected Output:
Actual Output:
Result:
The result will be a program that allows users to create bank accounts, perform transactions, and
manage customer and account information.
8
BIDISHA BISWAS
2203051240115
PRACTICAL - 2
AIM: A program that simulates a school management system,
with classes for the students, the teachers, and the courses.
Problem Statement:
Develop a program that simulates a school management system, modeling classes for students,
teachers, and courses. The system should allow for the creation of students and teachers,
enrollment in courses, grading, and tracking of academic information.
Program Description:
The program will use object-oriented programming to represent students, teachers, and courses.
Students can enroll in courses, teachers can assign grades, and the system will maintain academic
records for each student.
Algorithm:
1. Define a Student class with attributes like student ID, name, address, contact details, and a
method to enroll in courses.
2. Create a Teacher class with attributes such as teacher ID, name, subject expertise, and a method
to assign grades to students.
3. Implement a Course class with attributes like course code, course name, and a list of enrolled
students.
4. Develop a SchoolManagementSystem class to manage students, teachers, and courses, allowing
the creation of new students and teachers, enrollment in courses, and grading.
Source Code:
class Student:
def __init__(self, student_id, name, grade):
self.student_id = student_id
self.name = name
self.grade = grade
def display_info(self):
print(f"Student ID: {self.student_id}, Name: {self.name}, Grade: {self.grade}")
9
BIDISHA BISWAS
2203051240115
class Teacher:
def __init__(self, teacher_id, name, subject):
self.teacher_id = teacher_id
self.name = name
self.subject = subject
def display_info(self):
print(f"Teacher ID: {self.teacher_id}, Name: {self.name}, Subject: {self.subject}")
class Course:
def __init__(self, course_code, course_name, teacher, students):
self.course_code = course_code
self.course_name = course_name
self.teacher = teacher
self.students = students
def display_info(self):
print(f"Course Code: {self.course_code}, Course Name: {self.course_name}")
print("Teacher:")
self.teacher.display_info()
print("Students:")
for student in self.students:
student.display_info()
def main():
students = []
teachers = []
courses = []
print("""1.Sdutend_form/details
2.Teacher_form/details
3.Course_form/details""")
cho=int(input("Enter your choice: "))
if cho==1:
num_students = int(input("Enter the number of students: "))
for i in range(num_students):
student_id = input(f"Enter student {i + 1} ID: ")
name = input(f"Enter student {i + 1} name: ")
grade = input(f"Enter student {i + 1} grade: ")
students.append(Student(student_id, name, grade))
elif cho==2:
num_teachers = int(input("Enter the number of teachers: "))
for i in range(num_teachers):
teacher_id = input(f"Enter teacher {i + 1} ID: ")
name = input(f"Enter teacher {i + 1} name: ")
subject = input(f"Enter teacher {i + 1} subject: ")
teachers.append(Teacher(teacher_id, name, subject))
10
BIDISHA BISWAS
2203051240115
elif cho==3:
num_courses = int(input("Enter the number of courses: "))
for i in range(num_courses):
course_code = input(f"Enter course {i + 1} code: ")
course_name = input(f"Enter course {i + 1} name: ")
teacher_index = int(input("Enter the index of the teacher for this course: "))
teacher = teachers[teacher_index]
student_indices = input("Enter the indices of students for this course (comma-separated): ").split(",")
students_for_course = [students[int(index)] for index in student_indices]
courses.append(Course(course_code, course_name, teacher, students_for_course))
else:
print("Invalid input")
if __name__ == "__main__":
main()
Class Diagram:
11
BIDISHA BISWAS
2203051240115
Expected Output:
Actual Output:
Result:
The program successfully calculates the area and perimeter of a rectangle based on the user's
choice. It provides a user-friendly interface and accurate results for the calculations, meeting the
goal of creating a rectangle calculator.
12
BIDISHA BISWAS
2203051240115
PRACTICAL-3
AIM: A program that reads a text file and counts the number of
words in it.
Problem Statement:
Develop a program that reads a text file and counts the number of words in it.
Program Description:
The program will take a text file as input, read its content, and count the number of words. A word
is defined as any sequence of characters separated by whitespace.
Algorithm:
1. Open the text file in read mode.
2. Read the content of the file.
3. Tokenize the content based on whitespace to extract words.
4. Count the number of words.
5. Print the result.
Source Code:
def count(path):
try:
with open(path,'r') as file:
file_content = file.read()
return f"data = {file_content.split()}\nlength of the words: {len(file_content.split())}"
except FileNotFoundError:
return "Please Provide valid file path."
path ="example.txt"
print(count(path))
13
BIDISHA BISWAS
2203051240115
Expected Output:
Actual Output:
Result:
The result will be the count of words in the specified text file.
14
BIDISHA BISWAS
2203051240115
PRACTICAL - 4
AIM: A program that reads a CSV file and calculates the average of
Problem Statement:
Develop a program that reads a CSV file, extracts data from a specified column, and calculates
the average of the values in that column.
Program Description:
The program will take a CSV file as input, read its content, and allow the user to specify a column
for which the average should be calculated. It will then perform the necessary calculations and
display the average value.
Algorithm:
1. Accept the CSV file path and column name from the user.
2. Open and read the CSV file, extracting the specified column data.
3. Convert the column values to numerical format (assuming the values are numerical).
4. Calculate the average of the values in the specified column.
5. Display the result.
Source Code:
import csv
def calculate_average(csv_file, column_name):
try:
with open(csv_file, 'r') as file:
reader = csv.DictReader(file)
if column_name not in reader.fieldnames:
print(f"Column '{column_name}' not found in the CSV file.")
return None
total = 0
count = 0
for row in reader:
try:
value = float(row[column_name])
total += value
count += 1
except ValueError:
15
BIDISHA BISWAS
2203051240115
16
BIDISHA BISWAS
2203051240115
file.csv:
Expected Output:
Actual Output:
Result:
The result is the average value of the specified column in the provided CSV file. You can
customize and expand this program based on your specific requirements and the structure of your
CSV file.
17
BIDISHA BISWAS
2203051240115
PRACTICAL - 5
AIM: A program that reads an Excel file and prints the data in a tabular
format.
Problem Statement:
Develop a program that reads an Excel file and prints its data in a tabular format.
Program Description:
The program will take an Excel file as input, read its content, and display the data in a tabular
format. It may use libraries like openpyxl or pandas to handle Excel file operations.
Algorithm:
1. Accept the Excel file path from the user.
2. Open and read the Excel file.
3. Extract the data from the sheets.
4. Display the data in a tabular format.
Source Code:
import pandas as pd import openpyxl
output=pd.read_excel("delimited.xlsx")
print(output)
18
BIDISHA BISWAS
2203051240115
delimited.xlsx:
Expected Output:
19
BIDISHA BISWAS
2203051240115
Actual Output:
Result:
The result is the data from the Excel file displayed in a structured tabular format. You can
customize and extend this program based on your specific requirements and the structure of your
Excel file.
20