Answer to Question #243895 in Python for Sonu

Question #243895

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.


1
Expert's answer
2021-09-29T01:18:39-0400


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()

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS