0% found this document useful (0 votes)
97 views2 pages

U2 Mod2 Activity 2

The document outlines a Python module that focuses on sequence manipulation and list methods, including how to create lists, access list items, append and insert items into lists, and delete items from lists. Students will practice applying list methods like append through examples that demonstrate how to add items to the end of lists containing different data types. The module activities guide students through creating and modifying lists using methods like append and input to build up lists of currency values and birthdays from user input.

Uploaded by

Ansh Desai
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
97 views2 pages

U2 Mod2 Activity 2

The document outlines a Python module that focuses on sequence manipulation and list methods, including how to create lists, access list items, append and insert items into lists, and delete items from lists. Students will practice applying list methods like append through examples that demonstrate how to add items to the end of lists containing different data types. The module activities guide students through creating and modifying lists using methods like append and input to build up lists of currency values and birthdays from user input.

Uploaded by

Ansh Desai
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Unit II - Focuses on Python data structures such as strings, lists, and range sequences, as well as methods for

working with these structures. Students will be introduced to data structures and files in Python 3 and be ready for
more-advanced Python learning.

Module II – Sequence Manipulation

String Sequences Students will be able to:

 List Creation  Create Lists


 List Access  Access items in a list
 List Append  Add items to the end of a list
 List Insert  Modify and insert items into a list
 List Delete  Delete items from a list

Activity 2 List Append


1. Open Your IDE of Choice (Notebooks.Azzure, repl.It or Visual Studio
2. Open a New Project
3. Name it U2_M2_A1-XX (XX represents your first initial and last name I.E Mjordan).
4. Insert your program comments.
5. Insert a line comment to identify each step.
6. Watch This Video – Appending to Lists

Concept: Appending to Lists


.append() method adds an item to the end of a list

partyList.append("Alton")

Examples

7. # review, key and run example


a. sampleList = [1,1,2] #the list before append
b. print(“sampleList before: “, sampleList)
c. sampleList.append(3)
d. # the list after append
e. print(“sampleList after: “, sampleList)
8. # review, key and run example
#append number to sampleList
#run # 7 before running this example

a. Print(“sampleList start: “, sampleList)


b. sampleList.append(3)
c. Print(“sampleList added: “, sampleList)
d. #append again
e. sampleList.append(8)
f. Print(“sampleList added: “, sampleList)
g. #append again
h. sampleList.append(5)
i. Print(“sampleList added: “, sampleList)

9. # review, key and run example


a. mixedTypes = [1, “cat”]
b. #append number to mixedTypes
c. mixedTypes.append(3)
d. Print(“mixedTypes list: “, mixedTypes)
e. #append string to mixedTypes
f. mixedTypes.append(“turtle”)
g. Print(“mixedTypes list: “, mixedTypes)

10. Create a list of three currency values named curValues


a. Print the list
b. Append an item to the list and print the list
11. Create another list of three currency names named curNames (i.e.: quarter, dime, etc…)
a. Print the list
b. Append an item to the list and print the list

12. Append additional values to curNames list using input


a. Print curNames
b. Assign input to newValue for a currency denomination (i.e.: quarter, dime, etc…)
c. Append the currency names list with newValue
d. Print the appended list

13. Define an empty list bDaySurvey


a. Get user input asking for the day they were born (1-31) or “q” to finish
b. Use a while loop
i. Get user input asking for the day they were born (1-31) or “q” to finish
ii. Append the b day input to bDaySurvey
iii. Repeat input until “q” is entered
c. Print bDaySurvey

14. Identify and fix the error in the code below:


a. threeNumbers = [1,1,2]
b. print(“an item in the list is: “, threeNumbers[3])

15. Thoroughly test your code, check comments and then submit according to teacher instructions.
16. Take the activity quiz.

You might also like