====== Computer Lab 06, Modules and testing ====== ===== Practical work ===== ==== Celsius and Fahrenheit ==== Search the internet and find the conversion equations between the Celsius and Fahrenheit temperature scales. ==== Module ''temperature.py'' ==== Create module ''temperature.py'' with 2 functions: * ''celsius_to_fahrenheit(degrees_celsius)'' and * ''fahrenheit_to_celsius(degrees_fahrenheit)''. Specifications: * Function ''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. * Function ''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. ==== Test the functions ==== * Document the usage of the functions by examples in docstrings, and try to run them using the ''[[https://docs.python.org/3/library/doctest.html|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) * Optionally, implement test cases using module ''[[https://docs.python.org/3/library/unittest.html|unittest]]'', also from the standard library. * Optionally, use a simple testing tool implemented in module ''{{:courses:be5b33prg:labs:testing.py|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. ==== Convertor ==== Still in module ''temperature.py'', create a function ''convert'' which shall * accept a single string argument, e.g. '0C', '23.5C', or '122.1F' * return a similar string containing the temperature in the other scale, including the scale "identifier" ''C'' or ''F'' at the end of the string. * Test the function using the above 2 approaches again. ===== Homework ===== * Finish all the above tasks, and the tasks from last week, if you haven't finished them yet. * Finish [[courses:be5b33prg:homeworks:vectorlib|Homework 3: vectorlib]] and **upload** your solution to the upload system! See the deadline there! * Prepare for the midterm test! Its contents may be based on all the topics covered so far.