Loops, append() and break
Eg:
list_of_question = []
while True:
name = input("what is your name")
age = input("what is your age " )
platfrom = input("which os do u use ")
row = [name, age, platfrom]
list_of_question.append(row)
exit = input("Exit? y/n ")
if (exit.strip().lower()[0] == "y"):
break
print(list_of_question)
Add or Remove?
ask for a name on the list (make sure it is spelled correctly)extract each row, one at a time, from the listcheck the row to see if it contains the nameif the name is in the row, use the .remove() method to remove the whole row, not just the name.
Eg:
listOfShame = []
while True: menu = input("Add or Remove?")
if(menu.strip().lower()[0]=="a"): name = input("What is your name? ") age = input("What is your age? ") pref = input("What is your computer platform? ") row = [name, age, pref] listOfShame.append(row)
else: name = input("What is the name of the record to delete?") for row in listOfShame: if name in row: listOfShame.remove(row)
print(listOfShame)
listOfShame = []
while True:
menu = input("Add or Remove?")
if(menu.strip().lower()[0]=="a"):
name = input("What is your name? ")
age = input("What is your age? ")
pref = input("What is your computer platform? ")
row = [name, age, pref]
listOfShame.append(row)
else:
name = input("What is the name of the record to delete?")
for row in listOfShame:
if name in row:
listOfShame.remove(row)
print(listOfShame)
Comments
Post a Comment