William M. answered 05/31/23
Computer/HS Instructor w/7+ years teaching Computer Science


William M.
05/31/23
Bryce H.
asked 02/25/23Create 2 functions; one to convert a value from Fahrenheit to celsius and the second function to convert from celsius to Fahrenheit, remember to return the values in the function statement.
Create a new python file called ICE1.py. Using Import, import your new functions script in the ICE.py script.
Using the print() function, test and invoke the celsius and Fahrenheit functions.
William M. answered 05/31/23
Computer/HS Instructor w/7+ years teaching Computer Science
William M.
05/31/23
Chris W. answered 02/26/23
Experienced Software Engineer and CS Tutor
To start off with, lets create the functions skeleton and then import these functions. By first setting up a skeleton, you can test things out before we get into the logic of the conversions. When importing a python function from another file, you need to create all files in the same directory or use a relative path. For this example, we are going to put all python files in the same folder. Then, to import the functions, you can either use a * keyword to import all functions from a file, or you can explicitly list the functions you want to import. When creating the temp_functions.py file, we define the module's name with a '#' symbol. In the following example, we will explicitly name the functions we want to import.
Now, before we implement the logical section, lets test out the code is properly linked and calling the functions. I directly invoke the code with the python3 command from a terminal, but you can also use whatever IDE you prefer. Regardless the output should look like this:
Finally, lets implement the logic of the function and test it again to see that we get the right answer. I will only provide the pseudo code for the logic. The equations for these two conversions can be found online.
After you have plugged this in, try it out again using the same method as before, and you should get output similar to this:
Get a free answer to a quick problem.
Most questions answered within 4 hours.
Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.
William M.
05/31/23