-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInvoice.py
More file actions
45 lines (38 loc) · 1.49 KB
/
Invoice.py
File metadata and controls
45 lines (38 loc) · 1.49 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
class Invoice:
def __init__(self):
self.items = {}
def addProduct(self, qnt, price, discount):
self.items['qnt'] = qnt
self.items['unit_price'] = price
self.items['discount'] = discount
return self.items
def totalImpurePrice(self, products):
total_impure_price = 0
for k, v in products.items():
total_impure_price += float(v['unit_price']) * int(v['qnt'])
total_impure_price = round(total_impure_price, 2)
return total_impure_price
def totalDiscount(self,products):
total_discount = 0
for k, v in products.items():
total_discount += (int(v['qnt']) * float(v['unit_price']) * float(v['discount'])) / 100
total_discount = round(total_discount, 2)
return total_discount
def totalPurePrice(self, products):
total_pure_price = self.totalImpurePrice(products) - self.totalDiscount(products)
return total_pure_price
def inputAnswer(self, input_value):
while True:
userInput = input(input_value)
if userInput in ['y', 'n']:
return userInput
print("y or n! Try again.")
def inputNumber(self, input_value):
while True:
try:
userInput = float(input(input_value))
except ValueError:
print("Not a number! Try again.")
continue
else:
return userInput