+1 vote
in Class 12 by kratos

Write a class customer in Python Containing Deduct % Mark to be deducted if caldiscount () is following specifications. not invoked properly

  • Instance attributes: inside input( ) function customernumber – numeric value No mark to be deducted if member function customemame – string value definitions are written inside the class
  • price, qty discount, totalprice, netprice – numeric value methods :
  • init()-To assign initial values of customernumber as 111, customemame as “Leena”, qty as 0 and price, discount & netprice as 0.
  • caldiscount ( ) – To calculate discount, totalprice and netprice totalprice = price * qty
  • discount is 25% of totalprice, if totalprice >=50000
  • discount 15% of totalprice, if totalprice >=25000 and totalprice <50000
  • discount 10% of totalprice, if totalprice <250000 netprice= totalprice – discount
  • input()-to read data members customer- name, customernumber, price, qty and call caldiscount() to calculate discount, totalprice and netprice.
  • show( ) – to display Customer details.

1 Answer

+5 votes
by kratos
 
Best answer

class customer:

def init(self):

self.customemumber=111

self.customemame=‘Leena’

self.qty=0

self.price=0

self.discount=0

self.netprice=0

def caldiscount(self):

totalprice = self.price*self.qty

if totalprice >= 50000:

self.discount=totalprice * 0.25

elif totalprice >= 25000:

self.discount = totalprice * 0.15 else:

self.discount = totalprice * 0.10

self.netprice = totalprice – self.discount

def input(self):

self.customernumber=input(“Enter Customer Number”)

self.customemame = raw_input(“Enter Customer Name”)

self.qty = input(“Enter Quantity”)

self.price = input(“Enter Price”)

self.caldiscount()

def show(self):

print “Customer Number”,

self.customernumber

print “Customer Name”,

self.customemame

print “Quantity”,self.quanti-ty

print “Price”,self.price

print “Discount”,self.discount

print “Net price”,self.netprice

c = customer()

c.inputO c.show()

...