Professional Documents
Culture Documents
a. Write a Python program to create a Bank class where deposits and withdrawals
can be handled by using instance methods.
In [ ]: class Bank:
def __init__(self, balance=0):
self.balance = balance
def get_balance(self):
return f"Current balance: ${self.balance}"
# Example usage:
my_account = Bank(1000) # Create a Bank instance with an initial balance of $10
In [ ]: import numpy
import pandas
df = pandas.read_csv("C:\\Users\\Priyansh\\Desktop\\py_assignments\\online_retai
df.shape
Out[ ]: (541910, 8)
In [ ]: import numpy
import pandas
df = pandas.read_csv("C:\\Users\\Priyansh\\Desktop\\py_assignments\\online_retai
class Product:
def __init__(self, product_id, name, price):
self.product_id = product_id
self.name = name
self.price = price
def display_product_info(self):
return f"Product ID: {self.product_id}, Name: {self.name}, Price: {self.
class Customer:
def __init__(self, customer_id, name):
self.customer_id = customer_id
self.name = name
def display_customer_info(self):
return f"Customer ID: {self.customer_id}, Name: {self.name}"
def display_order_info(self):
product_info = self.display_product_info()
customer_info = self.display_customer_info()
return f"Order ID: {self.order_id}, Quantity: {self.quantity}\n{product_
# Method Overloading
def calculate_total(order):
if isinstance(order, Order):
return order.quantity * order.price
elif isinstance(order, list):
total = 0
for o in order:
if isinstance(o, Order):
total += o.quantity * o.price
return total
# Method Overriding
class DiscountedOrder(Order):
def __init__(self, order_id, product_id, customer_id, quantity, discount):
super().__init__(order_id, product_id, customer_id, quantity)
self.discount = discount
def display_order_info(self):
original_info = super().display_order_info()
return f"{original_info}\nDiscount: {self.discount}%"