Q. Create a module lengthconversion.py that stores functions for various lengths conversion
· miletokm() to convert miles to kilometers
· kmtomile() to convert kilometers to miles
· feettoinches()
· inchestofeet()
It should also store constant values such as value of (mile in kilometers and vice versa).
[I mile = 1.609344 kilometer ; 1 feet = 12 inches]
Help( ) function should display proper information.
You can understand by Watching video :-
Answer :-
one_mille_in_km = 1.609344 one_feet_in_inche = 12 def miletokm(x) : "Return value in kilometer from miles " return x * one_mille_in_km def kmtomile(x) : "Return value in miles from kilometer " return x / one_mille_in_km def feettoinches( x ): "Return value in inches from feet " return x / one_feet_in_inche def inchestofeet(x) : "Return value in feet from inches " return x * one_feet_in_inche
Output :-
>>> import lengthconversion as l
>>> l.miletokm( 1000 )
1609.344
>>> l.miletokm( 45628 )
73431.14803200001
>>> l.kmtomile( 1000 )
621.371192237334
>>> l.kmtomile( 74873 )
46523.925276385904
>>> l.feettoinches( 1000 )
83.33333333333333
>>> l.feettoinches( 35524 )
2960.3333333333335
>>> l.inchestofeet( 1000 )
12000
>>> l.inchestofeet( 24232 )
290784
>>> help( l )
Help on module lengthconversion:
NAME
lengthconversion
FUNCTIONS
feettoinches(x)
Return value in inches from feet
inchestofeet(x)
Return value in feet from inches
kmtomile(x)
Return value in miles from kilometer
miletokm(x)
Return value in kilometer from miles
DATA
one_feet_in_inche = 12
one_mille_in_km = 1.609344
FILE
c:\users\path walla\desktop\lengthconversion.py
>>>
Post a Comment
You can help us by Clicking on ads. ^_^
Please do not send spam comment : )