-
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 simple formatted string operations.
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 simple numeric calculations
- Using your IDE, or from within a terminal, create a new Python file - a module - named
SimpleFormattedStrings.pywithin thelabmodule02path (or package) - Open the module, and create the indicated test cases:
Test 1 (string append)
- Create a comment at the beginning of the file:
- For example:
# Test 1: String append test
- Declare the
salutationvariable as a string. Set the value to "Hello, World!" - Declare the
new_salutationvariable as a string. Its value will besalutationplus the string, " Good to meet you." - Print the
new_salutationstring. - Print the
new_salutationstring's length on a separate line.- E.g.,
print("New Salutation Length: ", len(new_salutation))
- E.g.,
Test 2 (string multiplication)
- Within the same module, add a blank newline after the previous test, and create another comment:
- For example:
# Test 2: String multiplication test
- Declare the
lots_of_applesvariable as a string. Set its value to "apples " and multiply by an integer (2 to 5 - your choice) - Print the variable
lots_of_apples
Test 3 (string formatting)
- Within the same module, add a blank newline after the previous test, and create another comment:
- For example:
# Test 3: String formatting test
- Declare the
selling_applesvariable as a formatted string (f-string). Here's the syntax:selling_apples = "{0} {1} {2}".format("i'm selling", lots_of_apples, "!")
- Print the
selling_applesstring - Now, print on a new line the
selling_applesstring, but call thecapitalize()function on the string. See if you can do this on your own.
Test 4 (string formatting w/ args)
- Within the same module, add a blank newline after the previous test, and create another comment:
- For example:
# Test 4: String formatting with arguments test
- Declare the
school_infovariable as a formatted string (f-string). Here's the syntax:school_info = "Location: {school}, {city}".format(school = "SCHOOL", city = "CITY")- NOTE: Replace
SCHOOLandCITYwith your choice of school and city.
- Print the
school_infostring - Append a state name to
school_info. Be sure to format it properly.
Estimate
- Small
Tests
-
From within your IDE
- Right click on your newly created module
SimpleFormattedStrings.pyand click your IDE'srunicon - 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_HOMEpath - Start your virtual environment (if not already running)
- Be sure your PYTHONPATH is set correctly
- Run the module
python ./labmodule02/SimpleFormattedStrings.py
- You should see output similar to that discussed in class
- Open a terminal and cd to your
Sample output (yours may differ slightly)
Hello, World! Good to meet you.
New Salutation Length: 31
apples apples apples
i'm selling apples apples apples !
I'm selling apples apples apples !
Location: Northeastern, Boston
Location: Northeastern, Boston, MA
Metadata
Metadata
Assignees
Labels
No labels
Type
Projects
Status
Lab Module 02 - Syntax