Below is the question and my attempted answer

5.4 Use the list of module titles from the previous exercise to create a for loop. It should ask the user for every title whether they would like to keep the title or delete it. Delete the titles which the user no longer wants.

Answer

# creating and modifying a list
#


module_list = ["Natural Language Processing", "Wireless Communication Systems", "Final Year Project", "Research Studies", "Internet Technologies", "Applied Mobile Technologies"]

nLoops = 6

for i in range(nLoops):

module_title = input(" Please enter a module title :  ")

new_item = input("Which item would you like to delete?\
Please input the name of the item: ")
if new_item in shopping_list:
      module_list.remove(new_item) 
      print (new_item, "has been deleted")
else: 
      print (new_item, "cannot be deleted because it is not in the module list")
print ("The module list has the following",\ len(module_list), "items:", module_list)

I keep getting an error expected an indented block.

Please help me fix this error and let me know if my code answers the 5.4 question

Thanks

Mark

erm! your solution does not really suit your task, try this one instead.

moduleList = ["software engineering", "applied mobile technologies", "research studies", "concurrent programming", "natural language processing", "final year project"]

for i in moduleList:
print (i)
yesNo = input("delete this module? Y/N: ")

if yesNo == "y" or yesNo == "Y":
  moduleList.remove(i)
  print ("the module has been deleted\n")

else:
    print ("no action taken\n")

print ("The module list now contains", len(moduleList), "modules:", moduleList)

p.s I got your own code running, you must indent as showen in the above solution.

p.p.s If this task is for Yuhua Li's class, then change it about to avoid plagiarism as I'm also in that class! Thanks.

This article has been dead for over six months. Start a new discussion instead.