ModuleSevenLessonOneActivityTwo.ipynb - Colaboratory

pdf

School

Smithfield-selma High *

*We aren’t endorsed by this school

Course

10

Subject

Computer Science

Date

Nov 24, 2024

Type

pdf

Pages

3

Uploaded by DukeDanger9183

Report
12/11/23, 10:11 AM ModuleSevenLessonOneActivityTw o.ipynb - Colaboratory https://colab.research.google.com/drive/1PkBai7Tnw 6Ck2ozncaVLA2QbDw _PHZ9u#scrollTo=ZJYtBgvLtQBd&printMode=true 1/3 I learned how to appen new thing to a list I did not have trouble with this lesson Lucas DuBois 11/27/23 List Append List Creation List Access List Append List Insert List Delete Student will be able to Create lists Access items in a list Add items to the end of a list Modify and insert items into a list Delete items from a list Before submission : Remember for max credit, you need to add a complete header comment in a code cell at the very top of this ±le and descriptive comments in each code cell below (examples AND tasks) that explains what your code is doing. ALL functions need a formatted docstring – see the bottom of Mod 3 Lesson 1 Activity for the requirements. Module Seven Lesson One Activity Two View Appending to Lists video .append() method adds an item to the end of a list party_list.append("Alton") Concept: Appending to Lists Examples # [ ] review and run example # the list before append sample_list = [1, 1, 2] print("sample_list before: ", sample_list) sample_list.append(3) # the list after append print("sample_list after: ", sample_list) sample_list before: [1, 1, 2] sample_list after: [1, 1, 2, 3] # [ ] review and run example # append number to sample_list print("sample_list start: ", sample_list) sample_list.append(3) print("sample_list added: ", sample_list) # append again sample list append(8)
12/11/23, 10:11 AM ModuleSevenLessonOneActivityTw o.ipynb - Colaboratory https://colab.research.google.com/drive/1PkBai7Tnw 6Ck2ozncaVLA2QbDw _PHZ9u#scrollTo=ZJYtBgvLtQBd&printMode=true 2/3 sample_list.append(8) print("sample_list added: ", sample_list) # append again sample_list.append(5) print("sample_list added: ", sample_list) # [ ] run this cell several times in a row # [ ] run cell above, then run this cell again sample_list start: [1, 1, 2, 3] sample_list added: [1, 1, 2, 3, 3] sample_list added: [1, 1, 2, 3, 3, 8] sample_list added: [1, 1, 2, 3, 3, 8, 5] # [ ] review and run example mixed_types = [1, "cat"] # append number mixed_types.append(3) print("mixed_types list: ", mixed_types) # append string mixed_types.append("turtle") print("mixed_types list: ", mixed_types) mixed_types list: [1, 'cat', 3] mixed_types list: [1, 'cat', 3, 'turtle'] Currency Values create a list of 3 or more currency denomination values, cur_values cur_values, contains values of coins and paper bills (.01, .05, etc.) print the list append an item to the list and print the list Task 1: .append() cur_values = [1.25, 2.50, 3.75] #Adds the currecny value in because it is apended in print(cur_values) cur_values.append(4.00) print(cur_values) [1.25, 2.5, 3.75] [1.25, 2.5, 3.75, 4.0] Currency Names create a list of 3 or more currency denomination NAMES, cur_names cur_names contains the NAMES of coins and paper bills (penny, etc.) print the list append an item to the list and print the list Task 2: .append() cur_names = ["penny", "nickel", "dime"] #It apends dollar into the currecny list print(cur_names) cur_names.append("dollar") print(cur_names) ['penny', 'nickel', 'dime'] ['penny', 'nickel', 'dime', 'dollar'] append additional values to the Currency Names list using input() print the appended list Task 3: Append items to a list with input()
12/11/23, 10:11 AM ModuleSevenLessonOneActivityTw o.ipynb - Colaboratory https://colab.research.google.com/drive/1PkBai7Tnw 6Ck2ozncaVLA2QbDw _PHZ9u#scrollTo=ZJYtBgvLtQBd&printMode=true 3/3 cur_names_input = input("Enter currency names: ") # it apends whatever you imput to the previous currency list cur_names.append(cur_names_input) print(cur_names) Enter currency names: Dime ['penny', 'nickel', 'dime', 'dollar', 'Dime'] de±ne an empty list: bday_survey get user input, bday , asking for the day of the month they were born (1-31) or "q" to ±nish using a while loop get user input, bday , asking for the day of the month they were born (1-31) or "q" to ±nish append the bday input to the bday_survey list repeat input until a user enters "q" to quit print bday_survey list Task 4: while loop .append() bday_survey=[] bday=input("please enter the day of the month you were born or 'q' to finish: ") #It apends the numbers you input into the list and whe while bday.lower() != 'q': bday_survey.append(bday) bday=input("please enter the day of the month you were born or 'q' to finish: ") print(bday_survey) please enter the day of the month you were born or 'q' to finish: 28 please enter the day of the month you were born or 'q' to finish: q ['28'] Remember to indicate in your comments what the issue was and how you ±xed it Task 5: Fix the error three_numbers = [1, 1, 2] print("an item in the list is: ", three_numbers[2]) # the wrong index was ion the box an item in the list is: 2 Terms of use Privacy & cookies © 2017 Microsoft
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help