Create a product class with product name, stock balance and price as attributes. include a constructer method (_init_) and also include methods for show data, issue product and get discount. Issue product must update stock balance by reducing it by a given quantity. Get discount must calculate and return 10% of price as discount. In the main program create two product objects and pass messages.
class Product:
def __init__(self, product_name, stock_balance, price):
self.product_name = product_name
self.stock_balance = stock_balance
self.price = price
def show_data(self):
print('Product name: ', self.product_name)
print('Stock balance: ', self.stock_balance)
print('Price', self.price)
def issue_product(self,quantity):
self.stock_balance-=quantity
def getDiscount(self):
return (self.price*0.1)
p1 = Product("Banana",20,345)
p1.show_data()
p1.issue_product(5)
print("Discount = ",p1.getDiscount())
p1.show_data()
p2 = Product("Apple",40,1200)
p2.show_data()
p2.issue_product(15)
print("Discount = ",p2.getDiscount())
p2.show_data()
Comments
Leave a comment