Write a program to calculate the electricity bill. The rates of electricity unit are as follows:
⮚ If the units consumed are <=300, then the cost is Rs. 2 per unit
⮚ If the units consumed are >300 and <= 500 then the cost is Rs. 5 per unit. ⮚ If the units consumed exceed 500 then the cost per unit is Rs. 7
A line rent Rs. 150 is also added of 5% extra if the bill exceeds Rs. 2000. Calculate the total bill with all conditions given above.
def calculate_bill(units):
cost = 0 # initialize cost
"""
calculate electricity bill based on the utilities
:param units:
:return: amount
"""
if units <= 300:
cost = (units * 2)
if 300 <= units <= 500:
cost = (units * 5)
if units > 500:
cost = (units * 7)
# if cost exceeds 2000
if cost > 2000:
cost += (0.05 * cost) + 150
return cost
if __name__ == "__main__":
bill = 200
amount = calculate_bill(bill)
print(amount)
Comments
Leave a comment