-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Description
Description
- Using instructions from the in-class lecture, update the
SimpleTempConversion.py
module with a Celsius to Fahrenheit conversion function.
Review the README
- Please see README.md for further information on, and use of, this content.
- License for embedded documentation and source codes: IPP-DOC-LIC
Estimated effort may vary greatly
- The estimated level of effort for this exercise shown in the 'Estimate' section below is a very rough approximation. The actual level of effort may vary greatly depending on your development and test environment, experience with the requisite technologies, and many other factors.
Actions
Step 1: Make Sure Your System is Setup for Python and This Course
- See IPP-CFG-01-001
Step 2: REMINDER: Make Sure PYTHONPATH is Set Correctly
Whether running Python tests within your IDE or from the command line, you must set the PYTHONPATH environment variable in every execution environment (e.g., every terminal you launch) when attempting to run any of your scripts and their tests or the IPP test app from the command line. The IPP source and test paths will be as follows:
- {your IPP source code path}
- {your IPP source code path}/tests
See IPP-DEV-01-001 for details.
Step 3: Edit the SimpleTempConversion.py
module you created in the previous exercise.
- Open the module, and implement the following test cases:
Test 1 (create two temperature conversion functions - F to C and C to F)
- Name one
convertTempFtoC()
- Name the other
convertTempCtoF()
- Here are the code examples:
def convertTempFtoC(tempInF: float = 0.0):
'''
Converts the passed in Farenheit temperature to Celsius.
Returns the result as a float.
Algorithm: C = 5/9 x (F - 32)
'''
# See if you can create this on your own.
# You may want to use the round() function as follows:
# round(some_number, 1)
# This will round the value to a single decimal place
# print the result - temp in F and temp in C
# return the temp in C float value
def convertTempCtoF(tempInC: float = 0.0):
'''
Converts the passed in Celsius temperature to Farenheit.
Returns the result as a float.
Algorithm: F = C x (9/5) + 32
'''
# See if you can create this on your own.
# You may want to use the round() function as follows:
# round(some_number, 1)
# This will round the value to a single decimal place
# print the result - temp in C and temp in F
# return the temp in F float value
- Test your converters to see if they work:
orig_f_val = 72.0
c_val = convertTempFtoC(orig_f_val)
f_val = convertTempCtoF(c_val)
print(f"Celsius = {c_val} and Farenheit = {f_val}. Original Farenheit is {orig_f_val}")
if (orig_f_val == f_val):
print("The temp converter works!")
else:
print("The temp converter failed!")
Estimate
- Medium
Tests
-
From within your IDE
- Right click on your newly created module
SimpleTempConversion.py
and click your IDE'srun
icon - You should see output similar to that discussed in class
- Right click on your newly created module
-
From the command line
- Open a terminal and cd to your
IPP_HOME
path - Start your virtual environment (if not already running)
- Be sure your PYTHONPATH is set correctly
- Run the module
python ./labmodule03/SimpleTempConversion.py
- You should see output similar to that discussed in class
- Open a terminal and cd to your
Sample output (yours may differ slightly)
Metadata
Metadata
Assignees
Labels
No labels
Type
Projects
Status
Lab Module 03 - Functions & Flow