Answer to Question #274471 in Python for M.R46

Question #274471

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.


1
Expert's answer
2021-12-02T06:47:03-0500
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)

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS