Skip to content

Instantly share code, notes, and snippets.

@gsusI
Last active August 8, 2023 15:53
Show Gist options
  • Save gsusI/127f4107cb3ebc862b8b674974291c26 to your computer and use it in GitHub Desktop.
Save gsusI/127f4107cb3ebc862b8b674974291c26 to your computer and use it in GitHub Desktop.
class Car:
def __init__(self, spec, production_emission_ton_co2e, emission_per_km_ton, distance_per_year_km):
self.spec = spec
self.production_emission_ton_co2e = production_emission_ton_co2e
self.emission_per_km_ton = emission_per_km_ton
self.distance_per_year_km = distance_per_year_km
def annual_emission(self):
return self.emission_per_km_ton * self.distance_per_year_km
def total_emission_over_years(self, years):
return self.production_emission_ton_co2e + (self.annual_emission() * years)
# Define constants
average_distance_per_year_km = 15000 # in kilometers
new_car_emission_per_km_ton = 150 * 1e-6 # Convert from grams to tons
old_car_emission_per_km_ton = 300 * 1e-6 # Convert from grams to tons
# The carbon footprint of a new car:
# 6 tonnes CO2e: Citroen C1, basic spec
# 17 tonnes CO2e: Ford Mondeo, medium spec
# 35 tonnes CO2e: Land Rover Discovery, top of the range
# Initialize the car objects with the different assumptions
new_car_basic = Car('basic', 6, new_car_emission_per_km_ton, average_distance_per_year_km)
new_car_medium = Car('medium', 17, new_car_emission_per_km_ton, average_distance_per_year_km)
new_car_high = Car('high', 35, new_car_emission_per_km_ton, average_distance_per_year_km)
old_car = Car('old', 0, old_car_emission_per_km_ton, average_distance_per_year_km)
print('Citroen C1, basic spec, total emissions over 10 years: {:.2f} tonnes CO2e'.format( new_car_basic.total_emission_over_years(10)))
print('Ford Mondeo, medium spec, total emissions over 10 years: {:.2f} tonnes CO2e'.format(new_car_medium.total_emission_over_years(10)))
print('Land Rover Discovery, top of the range, total emissions over 10 years: {:.2f} tonnes CO2e'.format(new_car_high.total_emission_over_years(10)))
print('Old car, total emissions over 10 years: {:.2f} tonnes CO2e'.format(old_car.total_emission_over_years(10)))
# Citroen C1, basic spec, total emissions over 10 years: 28.50 tonnes CO2e
# Ford Mondeo, medium spec, total emissions over 10 years: 39.50 tonnes CO2e
# Land Rover Discovery, top of the range, total emissions over 10 years: 57.50 tonnes CO2e
# Old car, total emissions over 10 years: 45.00 tonnes CO2e
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment