Home > Backend Development > Python Tutorial > Write a program to EB bill calculator

Write a program to EB bill calculator

DDD
Release: 2024-11-19 00:18:02
Original
748 people have browsed it

Write a program to EB bill calculator

Electricity Board bill calculator:

An Electricity Bill (EB) Calculator is a tool used to estimate the cost of electricity consumption based on the units consumed and applicable tariff rates.

Formula:
Electricity Cost = Electricity Consumption (kWh) x Tariff Rate per unit.

Example:

# Function to calculate electricity bill based on unit consumption
def eb(unit):
    # First 100 units are free
    if unit <= 100:
        cost = 0.00
    # For 101–200 units, charge ₹2.50 per unit above 100
    elif unit <= 200:
        cost = (unit - 100) * 2.50
    # For 201–300 units, add ₹3.00 per unit above 200
    elif unit <= 300:
        cost = 100 * 2.5 + (unit - 200) * 3.00
    # For 301–400 units, add ₹4.50 per unit above 300
    elif unit <= 400:
        cost = 100 * 2.5 + 100 * 3 + (unit - 300) * 4.50
    # For units above 400, add ₹6.00 per unit above 400
    else:
        cost = 100 * 2.5 + 100 * 3 + 100 * 4.5 + (unit - 400) * 6.00
    # Return the total calculated cost
    return cost

# input the total units consumed
unit = int(input("Enter the unit: "))

# Call the `eb` function to calculate the electricity bill
eb_bill = eb(unit)

# Display the calculated electricity bill amount
print("Electricity bill amount:", eb_bill)
Copy after login

Output:

Enter the unit:345
Electricity bill amount: 752.5
Copy after login

The above is the detailed content of Write a program to EB bill calculator. For more information, please follow other related articles on the PHP Chinese website!

source:dev.to
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template