-ICode (item code)
-Item (item name)
-Price (Price of each item)
-Qty (quantity in stock)
-Discount (discount percentage on the item)
-Net Price (final price)
--init—() : A construction to assign the value 0 for ICode, Price, Qy, Netprice and discount and null for item respectively.
buy() : to allow user to enter value for ICode, Item, Price, Qty and call the function find discount() to calculate the discount and the net price i.e. (Price*Qty-Discount)
find_discount() : to calculate discount as per following rule:
if Qty<=10, discount is 0
if Qty is between 11-20, discount is 15%
if Qty>=20, discount is 20%
show_all() : to allow user to view the content of all the data members.
In [ ]:
class ITEMINFO(object):
def __init__(self):
self.item = ''
self.icode = 0
self.price = 0
self.qty = 0
self.discount = 0
self.netprice = 0
def buy(self):
self.item = raw_input('Enter item name: ')
self.icode = int(raw_input('Enter item code: '))
self.price = int(raw_input('Enter price: '))
self.qty = int(raw_input('Enter quantity: '))
find_discount()
def find_discount(self):
if self.qty<=10:
self.discount = 0.0
elif 10<self.qty<20:
self.discount = 0.15
elif self.qty>20:
self.discount = 0.2
netprice = (self.price * self.qty) - (self.price * self.qty * self.discount)
def show_all(self):
print self.item + '\n' + 'Item code: ' + str(self.icode) + '\n' + 'Price: ' + str(self.price) + '\n' + 'Quantity: ' + str(self.qty) + '\n' + 'Net Price: ' + self.netprice