Question: Write a program that will calculate the user's carbon footprint for the year. You should have a different function for each component of the footprint.


Write a program that will calculate the user's carbon footprint for the year. You should have a different function for each component of the footprint. The user will input the several parts of their footprint: how the house is heated (wood, gas, propane, or electricity), car fuel (no car, electric, gas, diesel), then the relevant information. The relevant information needed will vary depending on the user's answer, and the calculations of the total carbon footprint will also vary. This is a complex problem - it is best to work on it one function at a time, see if it is working, and then move forward. You will need many different if statements. Write at least two tests for each function. Save & Run Original - 1 of 1 Show Feedback Hide Code 1 import test 2 def heating_footprint (heat_source, fuel_used): 3 # Calculate the heating carbon footprint. Return 0 if heat_sou. 4 # Wood is renewable. Electricity will be calculated under the 5 # For propane, 12.7 lbs CO2 / gal. For natural gas, 11.7 lbs C 6 CO2_emitted = 0 7 return co2_emitted 8 9 def electrical_footprint (KWH_used): 10 # calculate the electrical carbon footprint. In Iowa, 1 kwh fr 11 # This varies across the US depending on how much coal, natural 12 CO2_emitted = 0 13 return co2_emitted 14 15 def driving_footprint (driving_mode, miles_driven, mpg): # calculates the driving carbon footprint. We will assume that 16 TE 21. sta +1 5 16 15 def driving_footprint (driving_mode, miles_driven, mpg) : # calculates the driving carbon footprint. We will assume that 17 # If electric, this part of the carbon calculator can be o, as : 18 # gas 19.6 lbs co2 per gallon. 19 # diesel = 22.38 lbs CO2 per gallon. 20 CO2_emitted 0 21 return co2_emitted 22 23 def flying_footprint (miles_flown) : 24 # calculates the flying carbon footprint. Use .309 lbs co2 per 25 # This is a simplification: longer flights are more efficient i 26 CO2_emitted = 0 27 return co2_emitted 28 29 def main(): 30 hm = input ("How do you heat your home: enter for propane, Wi 31 dm = input ("What fuel does your car use: enter N for no car, E 32 33 # You'll need other inputs. You should make floats (especially i 34 heat_fuel_used = 0 # You'll need to ask for this. It will be 35 # You should use a different input statement depending on the i 36 37 kilowatt_hours_used 0 # You'll need to ask for this. 38 miles_driven 0 # you'll need to ask for this, unless they do 39 miles_per_gallon 1 # you'll need to ask for this, unless their 40 miles flown = 0 #you'll need to ask for this. 1 3 5 = 41 42 Testing heat function g 10 N Write a program that will calculate the user's carbon footprint for the year. You should have a different function for each component of the footprint. The user will input the several parts of their footprint: how the house is heated (wood, gas, propane, or electricity), car fuel (no car, electric, gas, diesel), then the relevant information. The relevant information needed will vary depending on the user's answer, and the calculations of the total carbon footprint will also vary. This is a complex problem - it is best to work on it one function at a time, see if it is working, and then move forward. You will need many different if statements. Write at least two tests for each function. Save & Run Original - 1 of 1 Show Feedback Hide Code 1 import test 2 def heating_footprint (heat_source, fuel_used): 3 # Calculate the heating carbon footprint. Return 0 if heat_sou. 4 # Wood is renewable. Electricity will be calculated under the 5 # For propane, 12.7 lbs CO2 / gal. For natural gas, 11.7 lbs C 6 CO2_emitted = 0 7 return co2_emitted 8 9 def electrical_footprint (KWH_used): 10 # calculate the electrical carbon footprint. In Iowa, 1 kwh fr 11 # This varies across the US depending on how much coal, natural 12 CO2_emitted = 0 13 return co2_emitted 14 15 def driving_footprint (driving_mode, miles_driven, mpg): # calculates the driving carbon footprint. We will assume that 16 TE 21. sta +1 5 16 15 def driving_footprint (driving_mode, miles_driven, mpg) : # calculates the driving carbon footprint. We will assume that 17 # If electric, this part of the carbon calculator can be o, as : 18 # gas 19.6 lbs co2 per gallon. 19 # diesel = 22.38 lbs CO2 per gallon. 20 CO2_emitted 0 21 return co2_emitted 22 23 def flying_footprint (miles_flown) : 24 # calculates the flying carbon footprint. Use .309 lbs co2 per 25 # This is a simplification: longer flights are more efficient i 26 CO2_emitted = 0 27 return co2_emitted 28 29 def main(): 30 hm = input ("How do you heat your home: enter for propane, Wi 31 dm = input ("What fuel does your car use: enter N for no car, E 32 33 # You'll need other inputs. You should make floats (especially i 34 heat_fuel_used = 0 # You'll need to ask for this. It will be 35 # You should use a different input statement depending on the i 36 37 kilowatt_hours_used 0 # You'll need to ask for this. 38 miles_driven 0 # you'll need to ask for this, unless they do 39 miles_per_gallon 1 # you'll need to ask for this, unless their 40 miles flown = 0 #you'll need to ask for this. 1 3 5 = 41 42 Testing heat function g 10 N
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
