Lists are a foundational data structure in computer programming. These assignments will help you practice using lists.
Submission Instructions
For each of the following practice assignments, save your solution in a .py file, with the name being lists and the number of the assignment. For example, for Lists01: Names, save your solution in a file named lists01.py. Then, submit that file the respective assignment on codePost.io.
Practice Assignments
Lists01: Names
Write a Python program that prompts the user for how many names to store in a list. Then, prompt the user that many times, storing each of the user's entries into a list named names. Display the names list. User input in bold
defmain():
''' Your solution goes here '''print( names )
main()
Lists02: Powers of 5
Complete the function powersOf5(). Have the function take a parameter n and return a list of the first n powers of 5. One way to calculate powers of 5 is by starting with 1 and then multiplying the previous number by 5.
Complete the oddNumbers() functions to take an int (as a parameter). Return a list of all of the odd numbers between 1 and one less than the parameter.
Also, complete the evenNumbers() functions to take an int (as a parameter). Return a list of all of the even numbers between 2 and one less than the parameter.
Examples:
oddNumbers( 9 ) returns [1, 3, 5, 7]
evenNumbers( 7 ) returns [2, 4, 6]
Provided code:
defoddNumbers():
defevenNumbers():
Lists04: Modify a list
Write the modifyList() function to delete the first element of names and change the last element to Ava.
Write a Python program to display an invitation to each of the people in the friends list, using a for loop.
Example:
Casey, please come to my party on Saturday
Riley, please come to my party on Saturday
Jessie, please come to my party on Saturday
Jackie, please come to my party on Saturday
Jaime, please come to my party on Saturday
Kerry, please come to my party on Saturday
Jody, please come to my party on Saturday
Provided code:
defmain( ):
# Display an invitation to each friend in the following list
friends = ['Casey', 'Riley', 'Jessie', 'Jackie', 'Jaime', 'Kerry', 'Jody']
main()
Lists08: Extra Credit Total
Complete the extraCreditTotal() function to take a list of grades as a parameter and return the total number points above 100.
Write a Python program that asks the user how many points to shift the grades in the
list
named
grades. Display each of the values in
grades (each on its own line), shifted by the value from the user.
Example 1:
Please enter the amount to shift the grades: 1
92
91
86
88
94
77
93
Example 2:
Please enter the amount to shift the grades: 5
96
95
90
92
98
81
97
Complete the isScrambled() function to return True if stringA can be reordered to make stringB. Otherwise, return False. Ignore spaces and capitalization. You must use a list for this assignment.
Write two functions, sumRows() and sumCols(), which each takes a two-dimensional list. sumRows() should return a list of totals for each row. sumCols() should return a list of totals for each column.
Hints:
You can assume that each row has the same number of elements.
How do you iterate through a 2D list?
Think about rows and columns, and how they correspond to a 2D list.
Provided code:
defsumRows():
defsumCols():
Lists13: Multiplication Table
Write a function makeMultiplicationTable() that takes two parameters, m and n, where m equals the number of rows and n equals the number of columns.
This function should return a two-dimensional list, where each element is the product of the row index plus 1 and the column index plus 1.