draftply Download

Petrol vs. Electric

← All samples

petrol-vs-electric.dplyEditor
1---
2app_version: 0.7.0
3precision: 2
4form_title: Petrol vs. electric
5form_description: Enter each car's consumption and the prices — the yearly cost of both, your savings and the EV's payback appear at once, with a comparison chart.
6form_inputs: Distance per year|km_year{km}, Petrol use|l_100{L/100km}, Petrol price|price_l{€/L}, Electric use|kwh_100{kWh/100km}, Electric price|price_kwh{€/kWh}
7form_outputs: Petrol per year (€)|petrol, Electric per year (€)|electric, You save (€)|saved, EV payback (years)|payback
8form_plots: 1
9---
10# Petrol vs. electric, per year
11// A road-trip cost comparison. This notebook also has a FORM (Pro): Form →
12// Form view for an input mask with the comparison chart built in.
13
14km_year = 15000 // driven per year
15
16# Petrol car
17l_100 = 7.0 // litres / 100 km
18price_l = 1.85 // € / litre
19petrol = km_year / 100 * l_100 * price_l
20
21# Electric car
22kwh_100 = 18 // kWh / 100 km
23price_kwh = 0.34 // € / kWh
24electric = km_year / 100 * kwh_100 * price_kwh
25
26# Verdict
27"Petrol per year (€)": petrol
28"Electric per year (€)": electric
29saved = petrol - electric
30You save {saved} € per year by driving electric.
31
32// If the EV costs 9000 € more to buy, it pays for itself in:
33payback = 9000 / saved
34
35# Bonus: unit math carries through
3615000 km in mi // same distance in miles
37"CO₂ from petrol (kg/yr)": km_year / 100 * l_100 * 2.31
38
39# Side by side
40// This is the chart the form embeds (form_plots: 1).
41Yearly fuel cost: bar([petrol, electric], "Petrol vs. electric", "car", "€ / year")
42