Search the internet and find the conversion equations between the Celsius and Fahrenheit temperature scales.
Create module temperature.py
with 2 functions:
celsius_to_fahrenheit(degrees_celsius)
and fahrenheit_to_celsius(degrees_fahrenheit)
.Specifications:
celsius_to_fahrenheit
shall accept a numeric argument representing a temperature in degrees Celsius and will return a numeric value representing the temperature in degrees Fahrenheit.
celsius_to_fahrenheit
shall accept a numeric argument representing a temperature in degrees Fahrenheit and will return a numeric value representing the temperature in degrees Celsius.
doctest
module. Inspire yourself in the following code:
# file average.py def average(x,y): """Return the average of 2 numbers. >>> average(10,20) 15.0 >>> average(1.5, 2.0) 1.75 """ return (x + y) / 2 if __name__ == "__main__": import doctest doctest.testmod(verbose=True)
unittest
, also from the standard library.
testing.py
. Create a test script test_temperature.py
that will use our testing.py
module to test the same situations that you used above to document the functions.
Still in module temperature.py
, create a function convert
which shall
C
or F
at the end of the string.