The purpose of these assignments is to help you review the concept of arrays in programming and hands-on practice of python Lists.
Utilize the lab sessions to work on these exercises, and reach out to your Teaching Assistant (TA) or instructor for help. You have unlimited attempts to solve and resubmit these assignments on codePost.io, so use this opportunity to learn, experiment, and improve.
Submission Instructions
For each of the following practice assignments, save your solution in a .py file, with the name being "lists" followed by the number of the assignment. For example, for "Lists01: Names", save your solution in a file named lists01.py (notice the lowercase "l"). Then, submit that file to the respective assignment on codePost.io .
There are two types of problems: Required and Optional/Bonus. The Required problems must be submitted to attain full credit for the codePost assignment, while Optional/Bonus problems are provided to help you practice further and deepen your understanding of Python.
To register for a free codePost account, please follow these instructions.
You can submit to codePost multiple times if you want.
Only your last submission will be graded.
From the starting date of this assignment, you have two weeks to complete and submit your solutions.
Watch this short video for a demonstration of submitting an assignment, reviewing the results and resubmitting.
Practice Assignments
Lists01: Names (Optional/Bonus)
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 (Required)
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 (Required)
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 (Required)
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 (Required)
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.