A2 Worksheet - Append and Remove Items
A2 Worksheet - Append and Remove Items
shopping.append("Bread")
Remove an item
shopping = ["bread", "cheese", "milk"]
shopping.remove("bread")
Task .
Step 1
Step 2
Use the append operator to add two new items to the shopping list:
● Eggs
● Flour
Step 3
Use the remove operator to remove cheese from the shopping list.
Step 4
Print your list to check that your code has worked. The output should look like
this:
● Continue to ask for new items until the user has finished
● Prompt if an item should be removed or added
● If the choice is to remove the item, it should remove it
● If the choice is to add the item, it should append it
● Display the finished list at the end of the program
Here is some example input and output to help you with your design:
Example
Note: Given the input you see in this sample interaction, this is the output your program
should produce.
The user is given a prompt Would you like to edit your shopping list? Y/N
The user is given a prompt Would you like to add or remove an item? A/R
The user is given a prompt Would you like to edit your shopping list? Y/N
The user is given a prompt Would you like to add or remove an item? A/R
The user is given a prompt Would you like to edit your shopping list? Y/N
The user is given a prompt Would you like to add or remove an item? A/R
The user is given a prompt Would you like to edit your shopping list? Y/N
Explorer task .
Revisit your ‘Simon says…’ program and add extra functionality to allow the
player to enter the movements for the game before they play.
Resources are updated regularly — the latest version is available at: ncce.io/tcc.
This resource is licensed under the Open Government Licence, version 3. For more information on this
licence, see ncce.io/ogl.