Q. Create a module conversion.py that should contain the following :-


Constant K = 273.15 # 0
degree C = 273.15 Kelvin

Two conversion functions:

function Cels_to_Fahr(tmp)

That converts given temperature in Celsius to temperature in Fahrenheit using formula:

°F = (9°F/5 °C)°C + 32 °F

and function Fahr_to_Cels(tmp)

That converts given temperature in Fahrenheit to temperature in Celsius using formula:

°C = (5 °C/9 °F) (°F - 32 °F)

Add proper docstring to the module.


(a) Code for conversion.py
(b) help(conversion) # give its output below as per your code of conversion.py


Answer :-


(a) Code :-

c = k = 273.15

def cels_to_Fahr(temp):
      """This function convert Celsius to Fahrenheit"""
      return str(((9 / 5)*temp) + 32) + "Fahrenheit"

def fahr_to_cels(temp):
      """This function convert Fahrenheit to Celsius"""
      return str((5/9)*(temp-32)) + "Celsius"

(b) Output :-


>>> import conversion
>>> help(conversion)

Help on module conversion:

NAME
    conversion
FUNCTIONS
    cels_to_Fahr(temp)
        This function convert Celsius to Fahrenheit
    
    fahr_to_cels(temp)
        This function convert Fahrenheit to Celsius

DATA
    c = 273.15
    k = 273.15

FILE
    c:\users\p w\desktop\ conversion.py

Post a Comment

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

Previous Post Next Post