Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Before you start this assignment, MAKE SURE you study the Course Setup and Instructions section of the course web page. In the Python shell, you

Before you start this assignment, MAKE SURE you study the
"Course Setup and Instructions" section of the course web page.
In the Python shell, you can use the following command to view the list class public interface:
dir(list)
You can use the following command to view descriptions for the list class methods:
help(list)
Make sure you test your program each time you add the code for a given task.
This is called incremental testing.
It is better to find errors early so you do not repeat them.
The starting contents of a data structure includes both its size and item values.
The expected output is based on the starting contents of myList.
I could change the starting contents of myList when I test your code.
You are NOT allowed to hard-code an answer to any part.
Your code should work if I change the starting contents of myList.
For example, for part 1, you must NOT have:
print (1)
print (6)
print (10)
For this part, you should use list indexing to print each item.
You are not allowed to re-initialization myList in any part.
Your code MUST progressively modify myList as specified in the comments.
Do NOT write code in any part like:
myList = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
or
myList = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]
or
myList = anything else
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Part 13:
# Use the following kind of "for" loop
# for x in myList:
# to print each item in the list on a separate line:
print()
print("Each item in list on a separate line:")
#
# Make sure your code prints your result.
# Part 14:
# Use a "for" loop to add 10 to each item in the list:
# Your "for" statement should be:
# for i in range(len(myList)):
# Inside your "for" loop you will use "i" as an index
# to reference the corresponding list item.
#
# NOTE: The following code will NOT work here.
##for x in myList:
## x += 10
# The reason is because numbers are immutable and each
# list entry itself is not changed.
# Only the x references are changed.
#
print()
print("Add 10 to each item in the list:")
#
print(myList)
# Part 15:
# Use a "for" loop to subtract 10 from each item in the list:
print()
print("Subtract 10 from each item in the list:")
#
print(myList)
# Part 16:
# Use the reverse() method to reverse the items in the list:
print()
print("Using reverse() to reverse the items in the list:")
#
print(myList)
~~~~~~~~~~~~~~~~~~~~
Output
myList:
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
Items at indexes 0, 5, and 9:
1
6
10
Length of list:
10
Using append() to add the number 5 to the end of the list:
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 5]
Length of list:
11
Using count() to find the number of times 5 occurs in the list:
2
Using pop() to remove the last item from the list:
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
Using remove() to remove the number 7 from the list:
[1, 2, 3, 4, 5, 6, 8, 9, 10]
Using insert() to insert the number 7 back in the list:
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
Using index() to find the index of the number 7 in the list:
6
Using min() to find the smallest item in the list:
1
Using max() to find the largest item in the list:
10
Using "in" to determine whether the number 7 is in the list:
True
Using "in" to determine whether the number 11 is in the list:
False
Each item in list on a separate line:
1
2
3
4
5
6
7
8
9
10
Add 10 to each item in the list:
[11, 12, 13, 14, 15, 16, 17, 18, 19, 20]
Subtract 10 from each item in the list:
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
Using reverse() to reverse the items in the list:
[10, 9, 8, 7, 6, 5, 4, 3, 2, 1]
Using sort() to sort the items in the list:
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
Using copy() to create a shallow copy of the list:
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
Using clear() to remove all the items from myList:
myList: []
copyList: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
Using extend() to extend myList with the contents of copyList:
myList: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
copyList: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Oracle9i Database Administrator Implementation And Administration

Authors: Carol McCullough-Dieter

1st Edition

0619159006, 978-0619159009

More Books

Students also viewed these Databases questions

Question

2. What is the difference between an embellishment and a lie?

Answered: 1 week ago

Question

Azure Analytics is a suite made up of which three tools?

Answered: 1 week ago