-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathPricePerUnitWeight.py
More file actions
63 lines (32 loc) · 1007 Bytes
/
PricePerUnitWeight.py
File metadata and controls
63 lines (32 loc) · 1007 Bytes
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
import sys
def main():
'''
Objective: To compute price per unit weight of an item
Input Parameter: None
Return Value: None
'''
price = float(input('Enter price of item purchased: '))
weight = float(input('Enter weight of item purchased: '))
try:
if price == '': price = None
try:
price = float(price)
except ValueError:
print('Invalid inputs: ValueError')
if weight == '': weight = None
try:
weight = float(weight)
except ValueError:
print('Invalid inputs: ValueError')
assert price >= 0 and weight >= 0
result =float(price / weight)
except TypeError:
print('Invalid inputs: TypeError')
except ZeroDivisionError:
print('Invalid inputs: ZeroDivisionError')
except:
print(str(sys.exc_info()))
else:
print('Price per unit weight: ', result)
if __name__ == '__main__':
main()