In Python: # Q1: create a list that has the following items. # {1, 2 , 3 , 4 , 5
ID: 3904942 • Letter: I
Question
In Python: # Q1: create a list that has the following items. # {1, 2 , 3 , 4 , 5} # you need to start with an empty list. and then add the above components # one by one. MyList = [ #create an empty list, 1 point MyList.-----(1) #add 1 to the list, 1 point MyList.-----(2) MyList.-----(3) MyList.-----(4) MyList.-----(5) # now find the length of the list. print(---(MyList)) # 1 point # select the starting and ending point such that it shows 2,3,4 print(MyList[-:-]) # 1 point # now, delet 1 from the list --- MyList[-]# 1 point # now, delete 3 from the list MyList.---()# 1 point
Explanation / Answer
ScreenShot
-------------------------------------------
Program
#Create empty list
MyList=[]
#add values one by one
MyList.append(1)
MyList.append(2)
MyList.append(3)
MyList.append(4)
MyList.append(5)
#print list
print("My list is:",MyList)
#Find length of the list
listLength=len(MyList)
print("Length of the list:",listLength)
#Get elements other than start and end
print("Elements other than start and end:",MyList[1:listLength-1])
#delete 1 from list
MyList.remove(1)
print("1 removed from the list:",MyList)
#delete 3 from list
MyList.remove(3)
print("3 removed from the list:",MyList)
---------------------------------
Output
My list is: [1, 2, 3, 4, 5]
Length of the list: 5
Elements other than start and end: [2, 3, 4]
1 removed from the list: [2, 3, 4, 5]
3 removed from the list: [2, 4, 5]
Press any key to continue . . .
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.