Question: Use Python Shell Window to answer questions 1 to 3 on a word file. Given: L = ['a', 7, 6, 5,Jack,3.4], write a statement for

Use Python Shell Window to answer questions 1 to 3 on a word file.

  1. Given: L = ['a', 7, 6, 5,"Jack",3.4], write a statement for each of the followings:
  1. a statement that prints the first element in the list
  2. a statement that prints the last element in the list
  3. a statement that prints [7, 6, 5] ; use the slicing operator.
  4. a statement that prints ['a', 7, 6] ; use the slicing operator.
  5. a statement that prints ["Jack", 3.4]; use the slicing operator.
  6. a statement that creates a copy of list L; use the slicing operator.
  7. A statement that prints all elements in List L in reverse order; use the slicing operator.

  1. Given: L1 = [1,3,2] and L2 = [7,8], write a statement for each of the followings:
  1. a statement that inserts 0 at the end of list L1; after inserting 0, L1 = [1,3,2,0].
  2. a statement that removes the second elements of list L1; after removing the second element, L1 = [1, 3].
  3. A statement that inserts the elements in list L2 at the end of list L1; after inserting 7, and 8, L1 = [1,3,2,7,8].
  4. A Statement that sort list L1; after sorting, L1 = [1,2,3].
  5. A statement that inserts 11 before index 2 in L1; after inserting 11, L1 = [1,3,11,2].
  6. A statement to remove 3 from list L1; after removing 3, L1 = [1,2].
  7. A statement that reverses L1; after L1 reversed L1 = [2,3,1].
  1. Answer the followings:
  1. Consider the following code:

list1=[1,2,99]

list2=list1

list3=list2

list1=list1.remove(1)

print(list3)

(a) What is printed?

(b) How can you change the code so list3 is unchanged?

  1. Consider:

ListA = [1,2,3,4,5]

ListB = ListA

ListA[2] = 10

What is the value of ListB[2]?

  1. Consider:

ListA = [1,2,3,4,5]

ListB = []

for num in ListA:

ListB.append(num)

ListA[2] = 10

(a) What is the value of ListB[2]?

(b) What is the value of ListB?

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!