Answered step by step
Verified Expert Solution
Question
1 Approved Answer
File: usePythonList.py Author: Derrf Seitz This program exercises Python built - in lists. # # Replace with your name.
File: usePythonList.py
Author: Derrf Seitz
This program exercises Python builtin lists.
#
# Replace with your name.
# Replace any comments with your own code statements
# to accomplish the specified task.
# DO NOT CHANGE ANY OTHER CODE.
# Here is your starting list:
myList
# Print the list:
printmyList:
printmyList
# Part :
# Print the items at indexes and :
print
printItems at indexes and :
printmyListmyListmyList
# Part :
# Use the len function to print the number of items in the list:
print
printLength of list:"
printlenmyList
# Part :
# Use the append method to add the number to the end of the list:
print
printUsing append to add the number to the end of the list:"
myList.append
printmyList
# Print the number of items in the list:
print
printLength of list:"
printlenmyList
# Part :
# Use the count method to print the number of times
# the number occurs in the list:
print
printUsing count to find the number of times occurs in the list:"
printmyListcount
# Make sure your code prints your result.
# Part :
# Use the pop method to remove the last item from the list:
# The last item is the one at index lenmyList
print
printUsing pop to remove the last item from the list:"
myList.pop
printmyList
# Part :
# Use the remove method to remove the number from the list:
# This will remove the first and only it finds.
print
printUsing remove to remove the number from the list:"
myList.remove
printmyList
# Part :
# Use the insert method to insert the number back in the list:
# Insert it where it is supposed to go which is at index
print
printUsing insert to insert the number back in the list:"
myList.insert
printmyList
# Part :
# Use the index method to find the index of the number in the list:
# This will be for the first and only it finds.
print
printUsing index to find the index of the number in the list:"
printmyListindex
# Make sure your code prints your result.
# Part :
# Use the min function to find the smallest item in the list:
print
printUsing min to find the smallest item in the list:"
printminmyList
# Make sure your code prints your result.
# Part :
# Use the max function to find the largest item in the list:
print
printUsing max to find the largest item in the list:"
printmaxmyList
# Make sure your code prints your result.
# Part :
# Use the in operation to determine whether the number is in the list:
print
printUsing in to determine whether the number is in the list:"
print in myList
# Make sure your code prints your result.
# Part :
# Use the in operation to determine whether the number is in the list:
print
printUsing in to determine whether the number is in the list:"
print in myList
# Make sure your code prints your result.
# Part :
# Use the following kind of "for" loop
for x in myList:
to print each item in the list on a separate line:
print
printEach item in list on a separate line:"
for x in myList:
printx
# Make sure your code prints your result.
# Part :
# Use a "for" loop to add to each item in the list:
# Your "for" statement should be:
for i in rangelenmyList:
# to reference the corresponding list item.
#
# NOTE: The following code will NOT work here.
# for x in myList:
# x
# The reason is because numbers are immutable and each
# list entry itself is not changed.
# Only the x references are changed.
#
print
printAdd to each item in the list:"
for i in rangelenmyList:
myListi
printmyList
# Part :
# Use a "for" loop to subtract from each item in the list:
print
printSubtract from each item in the list:"
for i in rangelenmyList:
myListi
printmyList
# Part :
# Use the reverse method to reverse the items in the list:
print
printUsing reverse to reverse the items in the list:"
#
printmyList
# Part :
# Use the sort method to sort the items in the list:
# The items are to be sorted back into their original ascending order.
print
printUsing sort to sort the items in the list:"
#
printmyList
# Use the copy method to create a shallow copy of the list:
# Name your copy copyList.
# Shallow copies can lead to problems when the items are mutable.
# For our list, its number items are immutable not mutable
print
printUsing copy to create a shallow copy of the list:"
copyList myList.copy
printcopyList
# Part :
# Use the clear method to remove all the items from myList:
print
printUsing clear to remove all
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started