forked from fenyx-it-academy/Class5-Python-Module-Week5
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWeek05_Hw_2.py
More file actions
80 lines (57 loc) · 2.42 KB
/
Week05_Hw_2.py
File metadata and controls
80 lines (57 loc) · 2.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
'''
Define a class named `ItemInfo` with the following description:
`item_code`(Item Code), `item`(item name), `price`(Price of each item), `qty`(quantity in stock),
`discount`(Discount percentage on the item), `net_price`(Price after discount)
**Methods :**
* A member method `calculate_discount()` to calculate discount as per the following rules:
* If `qty <= 10` —> discount is `0`
* If `qty (11 to 20 inclusive)` —> discount is `15`
* If `qty >= 20` —> discount is `20`
* A constructor init method to assign the initial values for
`item_code` to `0` and `price`, `qty`, `net_price` and `discount` to `null`
* A function called `buy()` to allow user to enter values for`item_code`, `item`, `price`, `qty`.
Then call function `calculate_discount()` to calculate the `discount` and `net_price`(price * qty - discount).
* A function `show_all()` or similar name to allow user to view the content of all the data members.
'''
class ItemInfo:
def __init__(self,item_code, item_name, price, qty, discount, net_price ):
self.item_code=item_code
self.item_name=item_name
self.price=price
self.qty=qty
self.discount=discount
self.net_price=net_price
def Buy(self):
self.item_code=input("Enter Item Code : ")
self.item_name=input("Enter Item Name : ")
self.price=float(input("Enter Price : "))
self.qty=int(input("Enter Quantity : "))
def calculate_discount(self):
if self.qty <= 10:
self.discount=0
#return self.discount
elif self.qty>11 and self.qty<20:
self.discount=15
#return self.discount
else:
self.discount=20
#return self.discount
self.net_price= (self.price*self.qty - self.discount)
self.discount
def __init__(self,item_code=None,price=None,qtr=None,discount=None,net_price=None):
self.item_code=item_code
self.price=price
self.qty=qtr
self.discount=discount
self.net_price=net_price
def Show_all(self):
print("Item Code : ", self.item_code)
print("Item Name : ", self.item_name)
print("Item Price : ", self.price)
print("Item Quantity : ", self.qty)
print("Item Discount : ", self.discount)
print("Item Net Price : ", self.net_price)
Item1=ItemInfo()
Item1.Buy()
Item1.calculate_discount()
Item1.Show_all()