Jan 19, 2026 | 307 words | 3 min read
11.2.3. Task 3#
Learning Objectives#
Perform set operations in Python (i.e., union, intersection, difference, etc); Use built-in data structures (i.e., lists, sets, strings); Employ the VS Code IDE to write, edit, and save Python code; Output Python data from script to screen.
Introduction#
In this task you will be writing a Python script that determines the relationship between characters in two words or phrases. You will be using sets to determine if the characters in the two words or phrases match. Ensure that you have reviewed the content on sets in Section 11.1.1 before starting this task.
Task Instructions#
Write a Python script that does the following:
Prompts the user to input two words or phrases (strings).
Convert each string to lowercase and remove any spaces (before, after, and within).
Convert each processed string to a set of characters.
Determine and print each of the following as sorted lists of characters:
The characters in the first string.
The characters in the second string.
The characters that are common to both strings.
The characters that are unique to the first string.
The characters that are unique to the second string.
Note
You may need to revisit the section on
list()in Section 11.1.1 to understand how to sort lists in Python.
Make a flow chart and save it as a PDF document named py1_team_3_teamnumber.pdf and write your code in the python template and rename it py1_team_3_teamnumber.py.
Sample Output#
Use the values in Table 11.6 below to test your program.
Case |
string1 |
string2 |
|---|---|---|
1 |
Hello |
World |
2 |
When is spring break? |
I want to go home! |
3 |
I am Lord Voldemort |
Tom Marvolo Riddle |
Ensure your program’s output matches the provided samples exactly. This includes all characters, white space, and punctuation. In the samples, user input is highlighted like this for clarity, but your program should not highlight user input in this way.
Case 1 Sample Output
$ python3 py1_team_3_teamnumber.py Enter the first string: Hello Enter the second string: World Characters in first string: ['e', 'h', 'l', 'o'] Characters in second string: ['d', 'l', 'o', 'r', 'w'] Characters in both strings: ['l', 'o'] Characters in the first string but not the second: ['e', 'h'] Characters in the second string but not the first: ['d', 'r', 'w']
Case 2 Sample Output
$ python3 py1_team_3_teamnumber.py Enter the first string: When is spring break? Enter the second string: I want to go home! Characters in first string: ['?', 'a', 'b', 'e', 'g', 'h', 'i', 'k', 'n', 'p', 'r', 's', 'w'] Characters in second string: ['!', 'a', 'e', 'g', 'h', 'i', 'm', 'n', 'o', 't', 'w'] Characters in both strings: ['a', 'e', 'g', 'h', 'i', 'n', 'w'] Characters in the first string but not the second: ['?', 'b', 'k', 'p', 'r', 's'] Characters in the second string but not the first: ['!', 'm', 'o', 't']
Case 3 Sample Output
$ python3 py1_team_3_teamnumber.py Enter the first string: I am Lord Voldemort Enter the second string: Tom Marvolo Riddle Characters in first string: ['a', 'd', 'e', 'i', 'l', 'm', 'o', 'r', 't', 'v'] Characters in second string: ['a', 'd', 'e', 'i', 'l', 'm', 'o', 'r', 't', 'v'] Characters in both strings: ['a', 'd', 'e', 'i', 'l', 'm', 'o', 'r', 't', 'v'] Characters in the first string but not the second: [] Characters in the second string but not the first: []
Deliverables |
Description |
|---|---|
py1_team_3_teamnumber.py |
Your completed Python code. |
py1_team_3_teamnumber.pdf |
Flowchart(s) for this task. |