Skip to main content



#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

Popular posts from this blog

How to make GUI dictionary in python

In application development, a dictionary  is an application that helps us with the meaning of a word by simply typing the word in a provided input box and clicking a button. Follow the steps below to get started. 1.   IMPORT THE NECESSARY MODULES AND LIBRARIES To be able to develop this application successfully, we need to first of all import the Tkinter module as shown in the coloured text below. Note, Tkinter comes already embedded in most python IDEs like Jupyter Notebook and Pycharm so requires no special installation. from tkinter import * Then import MessageBox . MessageBox as the name sounds helps us to display messages as popup in the event of an error or success or whatever you wish in your code. The syntax for importing the MessageBox is shown below. from tkinter import messagebox as MessageBox 2.  CREATE AND FORMAT A WINDOW (CONTAINER) FOR THE PROJECT window = Tk()  window.geometry("535x360")  window.title('Dictionary - St...