Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I need help with my assignment, This instructions are listed below but i am stil

ID: 3768811 • Letter: I

Question

I need help with my assignment, This instructions are listed below but i am still having some troublw grapsing the concept. I am thankfulfor any help with this! Script is listed below. Its a lot. THanks again for any help!

The point of this assignment is to learn what the following list functions do and how to use them.

.append( item )

.insert ( index, item )

.pop()

.pop(index)

.count( item )

.index( item )

.remove ( item )

.sort()

.reverse()

max(list) finds the largest value in the list

len(list) returns the length of the list

It involves a lot of typing. Enter the code fragments shown, and answer the questions in the comments (by modifying them or adding more comments).

#
# 1. Add this code and test it
# watch what it prints.
#
#---------------------------------------------------

print(" Append")
m = [10,8,1,3,6]


m.append (5)
m.append (6)
m.append (7)

print ("m is",m)


#----------------------insert----------------------------
#
# 2. Add this codes and test it.
# watch what it prints.
#
#---------------------------------------------------------

print(" Insert")
''' insert the number 100 before the 10 in the list '''
m.insert (0,100)

''' now insert the number 200 after the number 100 '''
m.insert (1,200)
print("After inserts, m is",m)


#-----------------------pop----------------------------------
#
# 3. Add this code and test it.
# fill in the comment bebeath the code.
#
#-------------------------------------------------------------

print(" Pop")
a = m.pop()
b = m.pop()
c = m.pop()


print("Values pooped: " a,b,c)
print("After popping, m is",m)

# What three values were popped? in what order?

# Notes
# A stack is a "last in first out" (lifo) structure where you "push" (append)
# things onto it (they go on the end) and then you "pop" (remove the end) data
#elements until the "stack" (list is empty.
#So to implement a stack , use append and pop to add to and remove items from
#the end
# A queue is a first in first out (filo) structure.
#To implement a queue, insert the item at the beginning and use pop to remove the
# item from the end.
#--------------------------------------------------------------------------------


#-------- using append and pop to make a stack------------------------------------
#
# 4. Add this code and test it.
# Fill in the comment beneath the code.
#
#
#---------------------------------------------------------------------------------

print(" Append and pop")
nStack = [];
nStack.append (1)
nStack.append (4)
nStack.append (40)
nStack.append (300)


a = nStack.pop()
b = nStack.pop()
c = nStack.pop()

print("Values popped from nStack:", a,b,c)
print("After popping, nStack is: ", nStack)

# What did a b and c equal?


#------------------using insert and pop to make a queue--------------
#
# 5. Enter this code and test it.
# Fill in the comment beneath the code.
#
#--------------------------------------------------------------------

print(" Insert and pop")
nQueue = []
nQueue.insert(0,1)
nQueue.insert(0,4)
nQueue.insert(0,40)
nQueue.insert(0,300)


x = nQueue.pop()
y = nQueue.pop()
z = nQueue.pop()

print("Values popped from nQueue: ", x,y,z)
print "After popping, nStack is: ", nQueue)

# What did a,b and c equal?


#------------------ pop from specific index position--------------
#
# 6. Enter thid code and test it.
#
# Fill in the comment beneath the code.
#
#----------------------------------------------------------------
print(" Pop(index)")
bList= [100,200,300]
x = bList.pop(1) #pop from position 1, not the last
print("Value popped from bList: ", x)
print("After popping, bList is: " bList)

# What two values are left in the bList?


#-------------- for loop-------------------------------------------
#
# 7. Add this code and test it.
# Fill in the comment benesth the code.
#
#-------------------------------------------------------------------

print(' For loop"
bList = [100,200,300]
sum = -0
for x in bList:
y = x*2
sum +=y
print(y)
print("Sum: ",sum)

# Describe what was printed.


#--------------------------max function-------------------
#
# 8. Add this code and test it.
# Fill in the comment benesth the code.
#
#----------------------------------------------------------

print(" Max")
bList = [100,200,300]
bList.append(345)
bList.append(234)
print('bList is: ", bList)
x = max (bList)
print("The max of bList is ",x)

# What does the max of bList equal?'''


#---------------------sort--------------------------------
#
# 9. Add this coed and test it.
# Fill in the comment beneath the code.
#
#----------------------------------------------------------

print(" Sort")
book=["Jaws", "Twillight", "Python 101"]
print("Before sort:",books)
books.sort()
print("After sort:".books)
print(book[-1]) # this prints the last value

# what does book [ -1] equal?


#--------------------reverse sort-----------------------------
#
# 10. Add this code and test it.
# Fill in the comment beneath the code.
#
#--------------------------------------------------------------

print(" Reverse")
books.append?("Where's Waldo")
books.append("Moby Dick")
print("Before reverse: ",boos)
books.reverse()
print("After reverse: ",books)
print(books[0] ) # this prints the first value


# What does books [0] equal?


#----------------------count----------------------------------
#
# 11. Add this code and test it
# Fill in the comment beneath the code.


print(" Count"
names= ["Bob","Chuck","Bob","Sally","Mary","bob"]
print(names)
x = names.count ("Bob")
print("Bob count = ",x)

#What is the bob count here?

#----------------------remove----------------------------
#
# 12. Add this code and test it.
# Fill in the comment beneath the code.
#
#---------------------------------------------------------

print(" Rmove")
names.remove ("Bob")
x = names.count ("Bob")
print(names)
print("Bob count = ", x)


# What is the Bob count here? '''''


#-----------------------------more about remove-----------------
#
#
# 13. Add this code and test it.
# Fill in the comment beneath the code.
#---------------------------------------------------------------


print(" Move removes")
names.remove ("Bob")
names.remove ("Bob")
x = names.count ("Bob")
print(names)
print("Bob count = ", x)
  
  
  
#----------------------preventing remove errors----------------
#
#
# 14. Just read this and understand it. Dont type it in.
# Unless you want to
#--------------------------------------------------------------


#--------------------index---------------------------------
# 15 . Add this code and test it.
# Fill in comment beneath the code.
#
#----------------------------------------------------------
print(" Index")
L = [9,6,8,5,2,6,8,6]
x = L.count(6)
y = L.index(6)
print(L)
print ("There are %d 6s. The first is at position %d" % (x,y) )

# What does . index do?
  

Explanation / Answer

I've added answers/output at the end of each question:

#
# 1. Add this code and test it
# watch what it prints.
#
#---------------------------------------------------
print(" Append")
m = [10,8,1,3,6]

m.append (5)
m.append (6)
m.append (7)
print ("m is",m)
#Append
#m is [10, 8, 1, 3, 6, 5, 6, 7]

#----------------------insert----------------------------
#
# 2. Add this codes and test it.
# watch what it prints.
#
#---------------------------------------------------------
print(" Insert")
''' insert the number 100 before the 10 in the list '''
m.insert (0,100)
''' now insert the number 200 after the number 100 '''
m.insert (1,200)
print("After inserts, m is",m)
#Insert
#After inserts, m is [100, 200, 10, 8, 1, 3, 6, 5, 6, 7]

#-----------------------pop----------------------------------
#
# 3. Add this code and test it.
# fill in the comment bebeath the code.
#
#-------------------------------------------------------------
print(" Pop")
a = m.pop()
b = m.pop()
c = m.pop()

print("Values pooped: ",a,b,c)
print("After popping, m is",m)
# What three values were popped? in what order?
#7 6 5
# Notes
# A stack is a "last in first out" (lifo) structure where you "push" (append)
# things onto it (they go on the end) and then you "pop" (remove the end) data
#elements until the "stack" (list is empty.
#So to implement a stack , use append and pop to add to and remove items from
#the end
# A queue is a first in first out (filo) structure.
#To implement a queue, insert the item at the beginning and use pop to remove the
# item from the end.
#--------------------------------------------------------------------------------

#-------- using append and pop to make a stack------------------------------------
#
# 4. Add this code and test it.
# Fill in the comment beneath the code.
#
#
#---------------------------------------------------------------------------------
print(" Append and pop")
nStack = [];
nStack.append (1)
nStack.append (4)
nStack.append (40)
nStack.append (300)

a = nStack.pop()
b = nStack.pop()
c = nStack.pop()
print("Values popped from nStack:", a,b,c)
print("After popping, nStack is: ", nStack)
# What did a b and c equal?
#300 40 4
#------------------using insert and pop to make a queue--------------
#
# 5. Enter this code and test it.
# Fill in the comment beneath the code.
#
#--------------------------------------------------------------------
print(" Insert and pop")
nQueue = []
nQueue.insert(0,1)
nQueue.insert(0,4)
nQueue.insert(0,40)
nQueue.insert(0,300)

x = nQueue.pop()
y = nQueue.pop()
z = nQueue.pop()
print("Values popped from nQueue: ", x,y,z)
print("After popping, nStack is: ", nQueue)
# What did a,b and c equal?
#1 4 40
#------------------ pop from specific index position--------------
#
# 6. Enter thid code and test it.
#
# Fill in the comment beneath the code.
#
#----------------------------------------------------------------
print(" Pop(index)")
bList= [100,200,300]
x = bList.pop(1) #pop from position 1, not the last
print("Value popped from bList: ", x)
print("After popping, bList is: ", bList)
# What two values are left in the bList?
#100 300
#-------------- for loop-------------------------------------------
#
# 7. Add this code and test it.
# Fill in the comment benesth the code.
#
#-------------------------------------------------------------------
print(" For loop")
bList = [100,200,300]
sum = -0
for x in bList:
y = x*2
sum +=y
print(y)
print("Sum: ",sum)
# Describe what was printed.
#twice the each element
#and sum of all the doubled elements
#--------------------------max function-------------------
#
# 8. Add this code and test it.
# Fill in the comment benesth the code.
#
#----------------------------------------------------------
print(" Max")
bList = [100,200,300]
bList.append(345)
bList.append(234)
print("bList is: ", bList)
x = max (bList)
print("The max of bList is ",x)
# What does the max of bList equal?'''
#345
#---------------------sort--------------------------------
#
# 9. Add this coed and test it.
# Fill in the comment beneath the code.
#
#----------------------------------------------------------
print(" Sort")
books=["Jaws", "Twillight", "Python 101"]
print("Before sort:",books)
books.sort()
print("After sort:",books)
print(books[-1]) # this prints the last value
# what does book [ -1] equal?
#Twillight
#--------------------reverse sort-----------------------------
#
# 10. Add this code and test it.
# Fill in the comment beneath the code.
#
#--------------------------------------------------------------

print(" Reverse")
books.append("Where's Waldo")
books.append("Moby Dick")
print("Before reverse: ",books)
books.reverse()
print("After reverse: ",books)
print(books[0] ) # this prints the first value

# What does books [0] equal?
#Moby Dick

#----------------------count----------------------------------
#
# 11. Add this code and test it
# Fill in the comment beneath the code.

print(" Count")
names= ["Bob","Chuck","Bob","Sally","Mary","bob"]
print(names)
x = names.count ("Bob")
print("Bob count = ",x)
#What is the bob count here?
#2
#----------------------remove----------------------------
#
# 12. Add this code and test it.
# Fill in the comment beneath the code.
#
#---------------------------------------------------------
print(" Rmove")
names.remove ("Bob")
x = names.count ("Bob")
print(names)
print("Bob count = ", x)
# What is the Bob count here? '''''
#1
#-----------------------------more about remove-----------------
#
#
# 13. Add this code and test it.
# Fill in the comment beneath the code.
#---------------------------------------------------------------

print(" Move removes")
names.remove ("Bob")
#names.remove ("Bob")
x = names.count ("Bob")
print(names)
print("Bob count = ", x)
#error Bob not in the list
  
  
#----------------------preventing remove errors----------------
#
#
# 14. Just read this and understand it. Dont type it in.
# Unless you want to
#--------------------------------------------------------------

#--------------------index---------------------------------
# 15 . Add this code and test it.
# Fill in comment beneath the code.
#
#----------------------------------------------------------
print(" Index")
L = [9,6,8,5,2,6,8,6]
x = L.count(6)
y = L.index(6)
print(L)
print ("There are %d 6s. The first is at position %d" % (x,y) )
# What does . index do?
#returns the position of first occurence of n in the list if it is present,
#else returns -1

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote