0% found this document useful (0 votes)
51 views

CCKP Python4

The document describes creating Python packages and modules for length and mass conversions. It involves: 1) Creating a Conversion file containing two packages - Length and Mass 2) The Length package contains a lengthconversion module with functions to convert between miles, km, feet and inches 3) The Mass package contains a MassConversion module with functions to convert between kg, tonnes and pounds
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
51 views

CCKP Python4

The document describes creating Python packages and modules for length and mass conversions. It involves: 1) Creating a Conversion file containing two packages - Length and Mass 2) The Length package contains a lengthconversion module with functions to convert between miles, km, feet and inches 3) The Mass package contains a MassConversion module with functions to convert between kg, tonnes and pounds
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

1.

Create the file named Length

2.Create the content of the file:

I.__init__.py #an empty python file

II.lengthconversion.py #the module

Content of lenthconversion.py:

'''Type C Program 1'''

print("welcome to lengthconversion module")

def miletokm(x):

y = x*1.609344

return(y)

def kmtomile(y):

x = y/1.609344

return(x)

def feettoinches(a):

b = a*12

return(b)

def inchestofeet(b):

a = b/12

return(a)
1.Create the file named Mass

2.Create the content of the file:

I.__init__.py #an empty python file

II.MassConversion.py #the module

Content of MassConversion.py:

'''This module helps in conversion of masses of various units:'''

def kgtotonne(x):

'''Convert kilogram to tonne.'''

y = x*0.001

return y

def tonnetokg(x):

'''Convert tonne to kilogram.'''

y = x/0.001

return y

def kgtopound(x):

'''Convert kilogram to pound.'''

y = x*2.20462

return y

def poundtokg(x):

'''Convert pound to kilogram.'''

y = x/2.20462

return y
1.Create a file named Conversion

2.1. Create a package named Length

2.2. Create a package named Mass

3.1. Create sub package of the file ‘Length’:

I.__init__.py #an empty python file

II.lengthconversion.py #the module

3.2. Create sub package of the file ‘Mass’:

I.__init__.py #an empty python file

II.MassConversion.py #the module

The content of the file lengthconversion.py:

'''Type C Program 1'''

print("welcome to lengthconversion module")

def miletokm(x):

y = x*1.609344

return(y)

def kmtomile(y):

x = y/1.609344

return(x)

def feettoinches(a):

b = a*12

return(b)

def inchestofeet(b):

a = b/12

return(a)
The content of MassConversion.py:

'''This module helps in conversion of masses of various units:'''

def kgtotonne(x):

'''Convert kilogram to tonne.'''

y = x*0.001

return y

def tonnetokg(x):

'''Convert tonne to kilogram.'''

y = x/0.001

return y

def kgtopound(x):

'''Convert kilogram to pound.'''

y = x*2.20462

return y

def poundtokg(x):

'''Convert pound to kilogram.'''

y = x/2.20462

return y

You might also like