#Object Oriented Programming (Python)
#SIMPLE PROFIT CALCULATOR -- StudySourceCodes.blogspot.com
class Sales:
def __init__(self, prodName,costPrice,sellingPrice):
self.prodName = prodName
self.costPrice = costPrice
self.sellingPrice = sellingPrice
#Getting coat price
def get_costPrice(self):
return self.costPrice
#Getting selling price
def get_sellingPrice(self):
return self.sellingPrice
class Product:
def __init__(self,prodCat,max_prods):
self.prodCat = prodCat
self.max_prods = max_prods
self.products = []
#Adding products to a list
def add_prods(self,product):
if len(self.products) < self.max_prods:
self.products.append(product)
print("Product successfully added!\n\n")
else:
print("Oops! This product has reached maximum number of products!")
#Calculating total profit
def get_tot_profit(self):
tot_profit = 0
for product in self.products:
profit = product.get_sellingPrice() - product.get_costPrice()
tot_profit += profit
return tot_profit
#Calculating average profit
def get_ave_profit(self):
total = 0
for product in self.products:
profit = product.get_sellingPrice() - product.get_costPrice()
total += profit
return total/len(self.products)
s1 = Sales("Water Heater",4500,7000)
s2 = Sales("Inverter",300000,450000)
#s3 = Sales("Electric Cooker",9000,15500)
p = Product("Appliances", 2)
p.add_prods(s1)
p.add_prods(s2)
#p.add_prods(s3)
print("Total Profit: ",int(p.get_tot_profit()))
print("Average Profit: ",int(p.get_ave_profit()))
Comments
Post a Comment