-
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 to test some of the basic functionality of Python's standard types - specifically, integers (int) and floats (float).
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 test standard Python numerics - int and float...
- Using your IDE, or from within a terminal, create a new Python file - a module - named
SimpleNumerics.py
within thelabmodule02
path (or package) - Open the module, and create the indicated test cases:
Test 1 (int)
- Create a comment at the beginning of the file:
- For example:
# Test 1: int
- Declare the
age
variable as an integer. Use a value between 20 and 100 - Declare the
count
variable as an integer. Use a negative value between -5 and -25 - Declare the
large_number
variable as an integer. Enter the value as1000000
- Declare the
alt_large_number
variable as an integer. Enter the value as1_000_000
- Print the variables to the console
- For example:
print(f"Age: {age}; Count: {count}; Large #: {large_number}; Alt Large #: {alt_large_number}")
Test 2 (float)
- Within the same module, add a blank newline after the previous test, and create another comment:
- For example:
# Test 2: float
- Declare the
price
variable as a float. Use a decimal value such as19.99
- Declare the
temperature
variable as a float. Use a decimal value such as72.4
- Declare the
sci_value
variable as a float. Use a decimal value with scientific notation such as1.23e-4
- Print the three variables to the console (
price
,temperature
, andsci_value
). You can use the example in Test 1 as a guide.
Test 3 (abs and conversion)
- Create a comment at the beginning of the file:
- For example:
# Test 3: abs() and conversion
- Re-declare the
price
variable as a float. Use a decimal value such as15.99
(anything is fine, as long as it contains decimals and is different from the initial declaration) - Declare the
price_no_cents
variable as an integer. Using the example covered in class, create the integer using theint()
function (it's actually a constructor), and passprice
in as the argument. - Declare the
price_with_cents
variable as a float. Using the example covered in class, create the float using thefloat()
function (it's actually a constructor), and passprice_no_cents
in as the argument. - Print the three variables to the console (
price
,price_no_cents
, andprice_with_cents
). You can use the example in Test 1 as a guide.
Estimate
- Small
Tests
-
From within your IDE
- Right click on your newly created module
SimpleNumerics.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 ./labmodule02/SimpleNumerics.py
- You should see output similar to that discussed in class
- Open a terminal and cd to your
Sample output (yours may differ slightly)
Age: 25; Count: -10; Large #: 1000000; Alt Large #: 1000000
Price: 19.99; Temperature: 72.4; Scientific Value: 0.000123
Absolute Count: 10
Price: 15.99; Price - no cents: 15; Price - back to cents: 15.0
Metadata
Metadata
Assignees
Labels
No labels
Type
Projects
Status
Lab Module 02 - Syntax