Sunday, May 24

"Miles per gallon" to "litres per 100 km" conversion

I'm tired of reading(or watching) mpg comparisions, when they don't give me a frame of reference. As such, I'd decided to write my own online convertor for it.

This is the algorithm (in python):
def mpg2lpckm(mpg):
one_mile=1.609344
one_gallon=3.78541178
kmpg = mpg * one_mile # km/gallon
kmpl = kmpg / one_gallon # km / l
lpkm = 1. / kmpl # l / km
return lpkm * 100.
and here is the online conversion:

No comments: