3.1.4.13 LAB: The basics of lists - the Beatles
LAB
Estimated time
10-15 minutes
Level of difficulty
Easy
Objectives
Familiarize the student with:
- creating and modifying simple lists;
- using methods to modify lists.
Scenario
The Beatles were one of the most popular music group of the 1960s, and the best-selling band in history. Some people consider them to be the most influential act of the rock era. Indeed, they were included in Timemagazine's compilation of the 20th Century's 100 most influential people.
The band underwent many line-up changes, culminating in 1962 with the line-up of John Lennon, Paul McCartney, George Harrison, and Richard Starkey (better known as Ringo Starr).
Write a program that reflects these changes and lets you practice with the concept of lists. Your task is to:
- step 1: create an empty list named
beatles
; - step 2: use the
append()
method to add the following members of the band to the list:John Lennon
,Paul McCartney
, andGeorge Harrison
; - step 3: use the
for
loop and theappend()
method to prompt the user to add the following members of the band to the list:Stu Sutcliffe
, andPete Best
; - step 4: use the
del
instruction to removeStu Sutcliffe
andPete Best
from the list; - step 5: use the
insert()
method to addRingo Starr
to the beginning of the list.
By the way, are you a Beatles fan?
beatles = []
ReplyDeleteprint("Step 1:", beatles)
beatles.append ("John_Lennon")
beatles.append ("Paul_McCartney")
beatles.append ("George")
beatles.append ("Harrison")
print("Step 2:", beatles)
for i in range (2):
if i == 0 :
beatles.append ("Stu_Sutcliffe")
else:
beatles.append ("Pete_Best")
print("Step 3:", beatles)
del beatles [4]
del beatles [4]
print("Step 4:", beatles)
beatles.insert (0, "Rigon_Starr")
print("Step 5:", beatles)
print("The Fab", len(beatles))
beatles=[]# step 1
ReplyDeleteprint("Step 1:", beatles)
beatles.append("John Lenon")
beatles.append("Paul McCartney")
beatles.append("George Harrison")
# step 2
print("Step 2:", beatles)
# step 3
for i in range(0,1):
var1=input("please enter StuSutcliffe to add it in the list of band")
beatles.append(var1)
var2=input("please enter Pete Best to add it in the list of band")
beatles.append(var2)
print("Step 3:", beatles)
# step 4
del beatles[-1]
del beatles[-1]
print("Step 4:", beatles)
# step 5
beatles.insert(0,"Ringo starr")
print("Step 5:", beatles)
# testing list legth
print("The Fab", len(beatles))
Why it didn't worked for
Deletedel beatles[4]