-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsolution15.py
More file actions
42 lines (33 loc) · 1.18 KB
/
solution15.py
File metadata and controls
42 lines (33 loc) · 1.18 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
"""
# ex.15
A cell phone company has the following billing policy
| | Fixed cost 25$ |
|---------|--------------|
| Call duration(in seconds)| Charge($/per second)|
| 1-500 | 0,01 |
| 501-800 | 0,008 |
| 801+ | 0,005 |
Create a program that:
* Reads how many seconds was the calls duration
* Calculates the monthly bill for the subscriber
* Prints the total amount
* Output: "total amount: 48$"
#### Notice that that the charge for the first 500 seconds it's 0,01$ then for the next 501 to 800 seconds
it's 0,008 and then it's 0,005$
"""
def calculate_montly_bill (calls_duration):
fixed_cost = 25
if calls_duration == 0:
bill = fixed_cost
elif calls_duration in range(1, 500):
bill = (calls_duration * 0.01) + fixed_cost
elif calls_duration in range(501, 800):
diff1 = calls_duration - 500 #where diff1 represents the next tier 501-800 sec
bill = (diff1 * 0.008) + (500 * 0.01) + fixed_cost
else:
diff2 = calls_duration - 800
bill = (diff2 * 0.005) + (300 * 0.008) + (500 * 0.01) + fixed_cost
return bill
seconds_duration = 800
amount = calculate_montly_bill (seconds_duration)
print(f"Total amount {amount}")