how to make API in python


I am going to make a middleware API system which integrate with Amazon API.

I am planning to use flask in python + mongodb + nginx for front end.

Demo site will be available hopefully soon here…

Digital Ocean

How to convert kilometer / liter to mpg: mpg = (km/lt) * 2.35214583

In the USA, MPG is an almost required index to see how efficient a car can get.
However, except USA, MPG is not so commonly used.
I find Europe and Japan uses kilometer per liter. Oops, how do we convert it to MPG?
Converting kilometer to miles and liter to gallons, then division?
It is very simple if you know some math, you notice all these conversions are linear, so you can make one time multiplication to convert it.

The simple equations are:

mpg = (km/lt) * 2.352
km/lt = mpg * 0.425


10 km/lt = 23.52 mpg
20 km/lt = 47.04 mpg

30 mpg = 12.75 km/lt
50 mpg = 21.25 km/lt

If you want to have more precision, this is for you:

#kilometer per liter to mpg

class kmpl2mpg: 
  def convert(kmpl):
    return kmpl * 2.35214583 # this is just a short cut
  convert = staticmethod(convert)

if __name__ == "__main__":
  import sys
    print 'KMPL2MPG(%.2f) = %.2f mpg' % (float(sys.argv[1]), kmpl2mpg.convert(float(sys.argv[1])))
    print 'usage: python 7.9'

Now you know Mercedes S400 Hybrid gets 29.64 mpg (12.6 km/liter)
Also you can check the result in google