Q. Create a module MassConversior.py that stores function for mass conversion e.g ,

·      A kgtotonne( ) to convert kg to tonnes

·      A tonnetokg() to convert tonne to kg

·      A kgtopound( ) to convert kg to pound

·      A poundtokg()to convert pound to kg

(Also store constants 1 kg - 0.001 tonne, 1 kg = 2.20462 pound)
Help( ) function should give proper information about the module.


You can understand by Watching video :-



Answer :-

one_kg_in_tonnes = 0.001
one_kg_in_pound = 2.20462

def  kgtotonne( x ):
    "Return value in tonne from kilogram"
    return x * one_kg_in_tonnes

def tonnetokg( x ) :
    "Return value in kilogram from tonnes"
    return x / one_kg_in_tonnes
def  kgtopound ( x ):
    "Return value pound from kilogram"
    return x * one_kg_in_pound

def  poundtokg( x ) :
    "Return value kilogram from pound"
    return x / one_kg_in_pound

Output :-

>>> import MassConversior as m
>>> m.kgtotonne( 1000 )
1.0
>>> m.kgtotonne( 1589 )
1.589
>>> m.tonnetokg( 698743 )
698743000.0
>>> m.tonnetokg( 2000 )
2000000.0
>>> m.kgtopound ( 5634 )
12420.82908
>>> m.kgtopound ( 1000 )
2204.62
>>> m.poundtokg( 796542 )
361305.80326768337
>>> m.poundtokg( 1000 )
453.59290943563974
>>> help(m)
Help on module MassConversior:

NAME
    MassConversior

FUNCTIONS
    kgtopound(x)
        Return value pound from kilogram
    
    kgtotonne(x)
        Return value in tonne from kilogram
    
    poundtokg(x)
        Return value kilogram from pound
    
    tonnetokg(x)
        Return value in kilogram from tonnes

DATA
    one_kg_in_pound = 2.20462
    one_kg_in_tonnes = 0.001

FILE
    c:\users\path walla\desktop\massconversior.py



>>>

Post a Comment

You can help us by Clicking on ads. ^_^
Please do not send spam comment : )

Previous Post Next Post