-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy path05. money_returned.py
40 lines (29 loc) · 1.06 KB
/
05. money_returned.py
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
'''
This module calculates the money to be returned given money paid, quantity purchased and price of commodity.
'''
def rtrn(a: float,b: int,c: float)-> float:
'''
Calculates the money to be returned given money paid, quantity purchased and price of commodity.
Args:
a(float): Money paid
b(int): Quantity purchased
c(float): Price of commodity
Returns:
float: Money to be returned
'''
return ( a - ( b * c ) )
try:
# Enter the amount of money paid
a: float= float(input("Enter the amount of money paid:- "))
# Enter the quantity purchased
b: int= int(input("Enter the quantity purchased:- "))
# Enter the price of commodity
c: float= float(input("Enter the price of commodity:- "))
if(a < b*c):
raise ValueError(f"Pay {b*c-a} more.")
# Calculating the amount to be returned using rtrn function
d: float= rtrn(a, b, c)
# Printing the amount to be returned
print(f"Amount to be returned is {d}")
except ValueError as e:
print(f"Error: {e}")