Energy Bill Calculator with Python

Опубликовано: 21 Октябрь 2024
на канале: DevSprout
891
9

Use this simple python script to calculate potential monthly energy costs using the information provided in EFL documents from various energy companies.

CODE:
def average_kwh_cost(kwh_charges, usage, base_charges):
total_cost = usage * sum(kwh_charges) + sum(base_charges)
return (total_cost / usage) * 100

kwh_charges = [float(x) for x in input("Enter kWh charges separated by space: ").split()]
usage = int(input("Enter monthly usage (kWh): "))
base_charges = [float(x) for x in input("Enter base charges separated by space: ").split()]

average_cost = average_kwh_cost(kwh_charges, usage, base_charges)
print("The average cost per kWh is: {:.2f} cents".format(average_cost))