# WTT emissions
WTT Maintenance emissions in tCO2e/km maintenance_emissions_per_km_ICEV = 8.34/1000/1000 maintenance_emissions_per_km_BEV = 4.17/1000/1000
WTT emissions, extraction refining and transportation wtt_per_liter_ICEV = { \"gasoline\": 680/1000/1000, # tCO2e/L \"diesel\": 980/1000/1000 # tCO2e/L }
WTT electricity mix electricity_generation_emissions_per_kWh = { \"Portugal\": 166/1000/1000, # tCO2e/kWh \"USA\": 369/1000/1000, # tCO2e/kWh \"China\": 582/1000/1000, # tCO2e/kWh \"Germany\": 381/1000/1000, # tCO2e/kWh \"Poland\": 662/1000/1000, # tCO2e/kWh \"Sweden\": 41/1000/1000, # tCO2e/kWh \"EU27 Average\": 229/1000/1000, # tCO2e/kWh \"Norway\": 30/1000/1000, # tCO2e/kWh \"France\": 56/1000/1000 # tCO2e/kWhVehicle fuel and electricity consumption consumption_per_100 km = { \"gasoline\": {  \"small\": 6.5/100, # 1/km  \"medium\": 7.5/100, # 1/km  \"large\": 8.8/100, # 1/km  },  \"diesel\": {  \"small\": 5.4/100, # 1/km  \"medium\": 6.2/100, # 1/km  \"large\": 6.7/100, # 1/km  },  \"BEV\": {  \"small\": 16/100, # kWh/km  \"medium\": 17.5/100, # kWh/km  \"large\": 19/100 # kWh/km  }  }  }  # Function to calculate total emissions for a given distance  def calculate_emissions(vehicle_type, size, distance, fuel_type=None,  battery_prod_loc=None, elec_mix=None):  if vehicle_type == \"ICEV\":  manufacturing = manufacturing_ICEV[fuel_type][size]  maintenance = maintenance_emissions_per_km_ICEV * distance  wtt = wtt_per_liter_ICEV[fuel_type] * distance * consumption_per_100 km[fuel_type][size]  tailpipe = tailpipe_emissions_per_liter_ICEV[fuel_type] * distance * consumption_per_100 km[fuel_type][size]  end_of_life = end_of_life_emissions[f'[size]_ICEV\"]  return manufacturing + wtt + maintenance + tailpipe + end_of_life  elif vehicle_type == \"BEV\":  manufacturing = manufacturing_BEV[size]  battery_production = battery_capacity[size] * battery_production_emissions[ battery_prod_loc]/1000 # tCO2e  maintenance = maintenance_emissions_per_km_BEV * distance # Adjust electricity use for charging losses  electricity_use = consumption_per_100 km[\"BEV\"][size] * distance * electricity_generation_emissions_per_kWh[elec_mix]*(1/0.857)  end_of_life = end_of_life_emissions[f'[size]_BEV\"]  return manufacturing + battery_production + maintenance + electricity_use + end_of_life
Finding the exact distance where BEV becomes more eco-friendly than ICEV  max_distance = 240000  countries = [\"Portugal\", \"USA\", \"China\", \"Germany\", \"Poland\", \"Sweden\", \"EU27  Average\", \"Norway\", \"France\"]  battery_locations = [\"Sweden\", \"South Korea\", \"USA\", \"China\", \"Battery Average\"]  results = []for size in [\"small\", \"medium\", \"large\"]:  
for fuel_type in [\"gasoline\", \"diesel\"]:  
for country in countries:  
for battery_loc in battery_locations:  
for distance in range(0, max_distance + 1):  
emissions_ICEV = calculate_emissions(\"ICEV\", size, distance,  
fuel_type=fuel_type)  
emissions_BEV = calculate_emissions(\"BEV\", size, distance,  
battery_prod_loc= battery_loc, elec_mix=country)  
if emissions_BEV <= emissions_ICEV:  
results.append((size, fuel_type, country, battery_loc, distance,  
emissions_BEV, emissions_ICEV))  
break  
print(\"Results for each scenario where BEV becomes more eco-friendly than ICEV:\") for record in results:  
size, fuel_type, country, battery_loc, distance, emissions_BEV, emissions_ICEV = record  
print(\"Vehicle Size: {size.capitalize()}, Fuel Type: {fuel_type.capitalize()}, Country:  
{country}, Battery Location: {battery_loc}, Distance: {distance} km, BEV Emissions:  
{emissions_BEV:2f} tCO2e, ICEV Emissions: {emissions_ICEV:2f} tCO2e\")