-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Description
Description
- Using instructions from the in-class lecture, create a module that will contain one (and eventually more) function(s) to handle simple temperature conversions.
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: Create your own module to contain temperature conversion functions.
- Using your IDE, or from within a terminal, create a new Python file - a module - named
SimpleTempConversion.py
within thelabmodule03
path (or package) - Open the module, and implement the following test cases:
Step 4: Document your functions using the Docstring spec PEP-0257
- You can comment your functions at any time, although I recommend you do so while you're developing the function - it's generally easier this way, as you'll remember what you did and why.
- Use the Docstring conventions listed in PEP-257
Test 1 (create the function framework)
- Create a multi-line comment at the beginning of the file:
"""
This module contains temperature conversion functions.
"""
- Declare two variables - representing min indoor temp and max indoor temp.
- Declare the
min_indoor_temp_F
variable as a float. Set the initial value to65.0
- Declare the
max_indoor_temp_F
variable as a float. Set the initial value to85.0
- Declare the
- Declare a function named
isDesiredIndoorTempRange()
.- It will accept a
float
calledtemp
and abool
calledis_celsius
. - It will return a
bool
.
- It will accept a
- The
isDesiredIndoorTempRange()
function will do the following:- It will compare the input
float
withmin_indoor_temp_F
andmax_indoor_temp_F
- if it's the same as either, or in between the two values, it will returnTrue
. - NOTE: We'll use the
is_celsius
bool
in a later exercise.
- It will compare the input
- Here's a partial example:
min_indoor_temp_F = 65.0
# implement the max setting yourself!
# partial implementation!
def isDesiredIndoorTempRange(temp, is_celsius):
if temp >= min_indoor_temp_F and temp <= max_indoor_temp_F:
print(f"Input temperature (F) is within desired indoor range: {temp}")
return True
print(f"Input temperature (F) is outside of desired indoor range: {temp}")
return False
Test 2 (create a simple test case)
- Test the
isDesiredIndoorTempRange()
function
isDesiredIndoorTempRange(70.0)
isDesiredIndoorTempRange(50.0)
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