EV Cost Savings and Efficiency Calculator

This interactive Python project gives the user a simple way to compare the costs of an EV compared to an ICE vehicle. It displays both short and long term savings, as well as the EV energy efficiency in ICE terms

The non-GUI version can be found here.

Objective

The goal of this project was to create a tool to compare the cost savings and efficiencies of electric vehicles (EVs) and internal combustion engine vehicles (ICEs). The currency, distance, and volume units automatically update depending on the selected efficiency unit.

Motivation

I wanted to develop this tool to help users, especially those unfamiliar with EV metrics, compare the efficiencies of electric vehicles and ICE vehicles in units they are already familiar with. By converting EV efficiency into miles per gallon equivalent (MPGe) or liters per 100 kilometers (L/100 km), the tool allows users to grasp the tangible savings and environmental benefits of switching to an EV.

Technical Overview

After selecting the efficiency unit and fuel type, the program saves these choices as global variables. The input fields and output results are then updated automatically to align with the typical usage of the selected unit system, such as €, L/100 km for Europe; £, Imperial MPG for the UK; and $, US MPG for the US.

The cost and efficiency parameters are calculated differently based on the selected efficiency unit.

The interactive GUI highlights the selected efficiency unit and fuel type for a better user experience. Error handling is built in to notify the user of any issues, such as an unselected, missing or invalid (non-numerical) input, as shown in the demonstration. This is achieved by running the user inputs through verification functions, displaying an error message if required.

Project Code


  • # EV Cost Savings and Efficiency Calculator

    # This program calculates the cost savings of using an electric vehicle (EV)

    # compared to an internal combustion engine (ICE) car based on user inputs.

    # It supports multiple regions with unit options in L/100km, Imperial MPG, or US MPG,

    # and displays appropriate currencies being for cost comparison.

    # The program also calculates EV fuel consumption equivalents in MPGe and L/100km.

    print ("EV Cost Savings Calculator")

    # Function to gather user inputs

    def get_user_input():

    fuel_cost = ice_efficiency = electricity_cost = ev_efficiency = annual_distance = 0

    fuel_unit = fuel_type = ""

    while True:

    # User selects fuel efficiency unit system (L/100km, Imperial MPG, or US MPG)

    fuel_unit = str(input("Select fuel efficiency unit: a) L/100 km, b) Imperial MPG, c) US MPG ")).strip().lower()

    if fuel_unit == "a": # Metric system: Liters per 100 km

    # Select fuel type (Petrol or Diesel) for ICE vehicle

    fuel_type = str(input("Select fuel type: a) Petrol, b) Diesel ")).strip().lower()

    if fuel_type in ("a", "b"):

    # Collect inputs for cost, efficiency, and annual distance

    fuel_cost = float(input("Enter fuel cost per liter: €"))

    ice_efficiency = float(input("Enter ICE efficiency (L/100 km): "))

    electricity_cost = float(input("Enter electricity cost per kWh: €"))

    ev_efficiency = float(input("Enter EV efficiency (km/kWh): "))

    annual_distance = float(input("Annual kilometers driven: "))

    break

    else:

    print("Invalid input. Please enter 'a' for Petrol or 'b' for Diesel.")

    elif fuel_unit == "b": # Imperial MPG

    # Select fuel type (Petrol or Diesel) for ICE vehicle

    fuel_type = str(input("Select fuel type: a) Petrol, b) Diesel ")).strip().lower()

    if fuel_type in ("a", "b"):

    fuel_cost = float(input("Enter fuel cost per liter: £"))

    ice_efficiency = float(input("Enter ICE efficiency (Imperial MPG): "))

    electricity_cost = float(input("Enter electricity cost per kWh: £"))

    ev_efficiency = float(input("Enter EV efficiency (miles/kWh): "))

    annual_distance = float(input("Annual mileage: "))

    break

    else:

    print("Invalid input. Please enter 'a' for Petrol or 'b' for Diesel.")

    elif fuel_unit == "c": # US gallon

    # Select fuel type (Gasoline or Diesel) for ICE vehicle

    fuel_type = str(input("Select fuel type: a) Gasoline, b) Diesel ")).strip().lower()

    if fuel_type in ("a", "b"):

    fuel_cost = float(input("Enter fuel cost per gallon: $"))

    ice_efficiency = float(input("Enter ICE efficiency (US MPG): "))

    electricity_cost = float(input("Enter electricity cost per kWh: $"))

    ev_efficiency = float(input("Enter EV efficiency (miles/kWh): "))

    annual_distance = float(input("Annual mileage: "))

    break

    else:

    print("Invalid input. Please enter 'a' for Gasoline or 'b' for Diesel.")

    else:

    print("Invalid input. Please enter either 'a', 'b', or 'c'.")

    return fuel_unit, fuel_type, fuel_cost, ice_efficiency, electricity_cost, ev_efficiency, annual_distance

    # Constants

    us_gallon = 3.785411784 # US gallons in liters

    imperial_gallon = 4.54609 # Imperial gallons in liters

    gasoline_energy = 33.705 # kWh per US gallon gasoline (petrol)

    diesel_energy = 37.950 # kWh per US gallon diesel

    # Conversions for units and energy

    conversion_factor = imperial_gallon / us_gallon # Conversion factor: US gallon to Imperial gallon

    gasoline_energy_imp = gasoline_energy * conversion_factor # Energy in kWh per Imperial gallon gasoline (petrol)

    diesel_energy_imp = diesel_energy * conversion_factor # Energy in kWh per Imperial gallon diesel

    kwh_per_liter_gasoline = gasoline_energy / us_gallon # Energy in kWh per liter gasoline (petrol)

    kwh_per_liter_diesel = diesel_energy / us_gallon # Energy in kWh per liter diesel

    # Function to calculate cost and efficiency parameters

    # Outputs cost per unit distance, energy efficiency equivalents, annual costs and savings.

    def calculate_parameters(fuel_unit, fuel_type, fuel_cost, ice_efficiency, electricity_cost, ev_efficiency, annual_distance):

    if fuel_unit == "a": # Metric system

    # Calculations for cost per 100 km and annual cost

    ice_fuel_cost_per_100km = fuel_cost * ice_efficiency

    ev_energy_cost_per_100km = electricity_cost * (100 / ev_efficiency)

    ice_annual_cost = (ice_fuel_cost_per_100km / 100) * annual_distance

    ev_annual_cost = (ev_energy_cost_per_100km / 100) * annual_distance

    annual_savings = ice_annual_cost - ev_annual_cost

    ev_kwh_per_100km = 100 / ev_efficiency

    percentage_savings = ((ice_annual_cost - ev_annual_cost) / ice_annual_cost) * 100

    # Calculations for ICE kWh consumption and EV equivalent

    ice_kwh_per_100km = None

    if fuel_type == "a": # Petrol

    ice_kwh_per_100km = ice_efficiency * kwh_per_liter_gasoline # kWh/100 km for petrol (gasoline)

    ev_l_per_100km_equivalent = (ev_kwh_per_100km / ice_kwh_per_100km) * ice_efficiency

    print(f"EV equivalent energy efficiency: {ev_l_per_100km_equivalent:.2f} L petrol / 100 km") # EV equivalent petrol L/100 km

    elif fuel_type == "b": # Diesel

    ice_kwh_per_100km = ice_efficiency * kwh_per_liter_diesel # kWh/100 km for diesel

    ev_l_per_100km_equivalent = (ev_kwh_per_100km / ice_kwh_per_100km) * ice_efficiency

    print(f"EV equivalent energy efficiency: {ev_l_per_100km_equivalent:.2f} L diesel / 100 km") # EV equivalent diesel L/100 km

    # Output results

    print(f"ICE cost per 100 km: €{ice_fuel_cost_per_100km:.2f}")

    print(f"EV cost per 100 km: €{ev_energy_cost_per_100km:.2f}")

    print(f"ICE annual cost: €{ice_annual_cost:.2f}")

    print(f"EV annual cost: €{ev_annual_cost:.2f}")

    print(f"Annual savings: €{annual_savings:.2f}")

    print(f"5 year savings: €{5 * annual_savings:.2f}")

    print(f"10 year savings: €{10 * annual_savings:.2f}")

    if ice_annual_cost > ev_annual_cost:

    print(f"The EV is {percentage_savings:.2f} % cheaper than the ICE vehicle")

    else:

    print("The EV is not cheaper than the ICE vehicle given the current costs and efficiencies")

    elif fuel_unit == "b": # Imperial MPG

    # Calculations for cost per 100 miles and annual cost

    fuel_cost_per_gallon = fuel_cost * imperial_gallon # £ per liter to £ per imperial gallon

    ice_fuel_cost_per_mile = fuel_cost_per_gallon / ice_efficiency # ICE cost per mile

    ev_energy_cost_per_mile = electricity_cost / ev_efficiency # EV cost per mile

    ice_annual_cost = (annual_distance / ice_efficiency) * fuel_cost_per_gallon

    ev_annual_cost = ev_energy_cost_per_mile * annual_distance

    annual_savings = ice_annual_cost - ev_annual_cost

    percentage_savings = ((ice_annual_cost - ev_annual_cost)/ice_annual_cost) * 100

    # Calculations for ICE kWh consumption and EV equivalent

    if fuel_type == "a": # Petrol

    ev_mpg_equivalent = ev_efficiency * gasoline_energy_imp

    print(f"EV petrol equivalent energy efficiency: {ev_mpg_equivalent:.2f} MPGe")

    elif fuel_type == "b": # Diesel

    ev_mpg_equivalent = ev_efficiency * diesel_energy_imp

    print(f"EV diesel equivalent energy efficiency: {ev_mpg_equivalent:.2f} MPGe")

    # Output results

    print(f"Ice cost per mile: £{ice_fuel_cost_per_mile:.2f}")

    print(f"EV cost per mile: £{ev_energy_cost_per_mile:.2f}")

    print(f"ICE annual cost: £{ice_annual_cost:.2f}")

    print(f"EV annual cost: £{ev_annual_cost:.2f}")

    print(f"Annual savings: £{annual_savings:.2f}")

    print(f"5 year savings: £{5 * annual_savings:.2f}")

    print(f"10 year savings: £{10 * annual_savings:.2f}")

    if ice_annual_cost > ev_annual_cost:

    print(f"The EV is {percentage_savings:.2f} % cheaper than the ICE vehicle")

    else:

    print("The EV is not cheaper than the ICE vehicle given the current costs and efficiencies")

    elif fuel_unit == "c": # US MPG

    # Calculations for cost per 100 miles and annual cost

    ice_fuel_cost_per_mile = fuel_cost / ice_efficiency # $ per gallon / MPG

    ev_energy_cost_per_mile = electricity_cost / ev_efficiency # $ per kWh / miles per kWh

    ice_annual_cost = ice_fuel_cost_per_mile * annual_distance

    ev_annual_cost = ev_energy_cost_per_mile * annual_distance

    annual_savings = ice_annual_cost - ev_annual_cost

    percentage_savings = ((ice_annual_cost - ev_annual_cost) / ice_annual_cost) * 100

    # Calculations for ICE kWh consumption and EV equivalent

    if fuel_type == "a": # Gasoline

    ev_mpg_equivalent = ev_efficiency * gasoline_energy

    print(f"EV gasoline equivalent energy efficiency: {ev_mpg_equivalent:.2f} MPGe")

    elif fuel_type == "b": # Diesel

    ev_mpg_equivalent = ev_efficiency * diesel_energy

    print(f"EV diesel equivalent energy efficiency: {ev_mpg_equivalent:.2f} MPGe")

    # Output results

    print(f"Ice cost per mile: ${ice_fuel_cost_per_mile:.2f}")

    print(f"EV cost per mile: ${ev_energy_cost_per_mile:.2f}")

    print(f"ICE annual cost: ${ice_annual_cost:.2f}")

    print(f"EV annual cost: ${ev_annual_cost:.2f}")

    print(f"Annual savings: ${annual_savings:.2f}")

    print(f"5 year savings: ${5 * annual_savings:.2f}")

    print(f"10 year savings: ${10 * annual_savings:.2f}")

    if ice_annual_cost > ev_annual_cost:

    print(f"The EV is {percentage_savings:.2f} % cheaper than the ICE vehicle")

    else:

    print("The EV is not cheaper than the ICE vehicle given the current costs and efficiencies")

    # Main program function

    def main():

    fuel_unit, fuel_type, fuel_cost, ice_efficiency, electricity_cost, ev_efficiency, annual_distance = get_user_input()

    calculate_parameters(fuel_unit, fuel_type, fuel_cost, ice_efficiency, electricity_cost, ev_efficiency, annual_distance)

    if name == "__main__":

    main()