Drop links or images here to add them to the editor.

In a modify task you take code that already works and adapt it so that it does something else.

The editor starts you off with one line: a list of four video games.

video_games = ["Mario", "Sonic", "Joust", "Zelda"]

Your task

Adapt the code so that it does all of the following, in this order.

  1. Add Minecraft to the start of the list. Do not retype the list: add the item to the list that is already there. After this step the list holds five games, with Minecraft at index 0.
  2. Ask the user for a number between 0 and 4, and print the item at that position in the list. Ask the question with its own print, exactly as written:
    Enter a number between 0 and 4:
    

    Read the answer with a bare input() and cast it with int().

  3. Ask the user for the name of a video game, with its own print, exactly as written:
    Enter the name of a video game:
    

    Read the answer with a bare input().

    • If that game is in the list, remove it from the list.
    • If it is not in the list, add it to the end of the list.
  4. Print the whole list, so that the change made in step 3 can be seen.

The output

Both questions are printed exactly as written above, followed by three more lines.

The first of those three is the item at the position the user asked for, printed on its own, as in:

Minecraft

The second says what happened to the game the user named. NAME stands for exactly what the user typed:

NAME has been removed from the list
NAME has been added to the list

The third is the whole list, printed in one go, which Python shows with its square brackets, quotes and commas:

['Minecraft', 'Mario', 'Joust', 'Zelda']

The name of a game is matched exactly as it is typed, capital letters included, so sonic is not the same game as Sonic. A game typed any other way is one that is not in the list, so it gets added to the end.

Example

Input:

0
Sonic

Output:

Enter a number between 0 and 4:
Minecraft
Enter the name of a video game:
Sonic has been removed from the list
['Minecraft', 'Mario', 'Joust', 'Zelda']

Input:

4
Fortnite

Output:

Enter a number between 0 and 4:
Zelda
Enter the name of a video game:
Fortnite has been added to the list
['Minecraft', 'Mario', 'Sonic', 'Joust', 'Zelda', 'Fortnite']

Input:

2
Minecraft

Output:

Enter a number between 0 and 4:
Sonic
Enter the name of a video game:
Minecraft has been removed from the list
['Mario', 'Sonic', 'Joust', 'Zelda']

(the game the user names can be the one that was added in step 1)


Input:

3
sonic

Output:

Enter a number between 0 and 4:
Joust
Enter the name of a video game:
sonic has been added to the list
['Minecraft', 'Mario', 'Sonic', 'Joust', 'Zelda', 'sonic']

(sonic is not Sonic, so it is not in the list and gets added)

Both questions are part of the output that is checked here, so their spelling, capital letters and punctuation count. Ask each one with its own print, exactly Enter a number between 0 and 4: and Enter the name of a video game:, and read the answer with a bare input() on the next line, rather than passing the question to input(...).

List operations

Operation What it does How to code it
Output item Outputs a single item from the list. print(list_name[item_index])
print(sweets[3])
Edit item Changes or replaces an item in the list. list_name[item_index] = new data
sweets[1] = "Haribo"
Add an item Puts a new item onto the end of the list. list_name.append(new data)
sweets.append("Galaxy")
Remove an item Removes an item from the list, either by its index or by the data itself. list_name.pop(item_index)
sweets.pop(2)
list_name.pop()
list_name.remove(item)
sweets.remove("Haribo")
Output all items Outputs every item in the list, one by one, using a loop. for i in range(0, len(list_name)):
    print(list_name[i])

for i in range(0, len(sweets)):
    print(sweets[i])

Python also has a built in shortcut that prints the whole list in one line:
print(sweets)
Help! My code doesn't work!

Make sure that you check for the following things:

  • The list name is spelled identically everywhere it is used, capital letters included.
  • The index is surrounded by square brackets.
  • List indexing starts at zero. Are you counting properly?
  • Minecraft goes at the start of the list, so it needs insert with an index of 0, not append.
  • The number the user types is wrapped in int() before it is used as an index.
  • The five lines are printed in the order given above.
  • Every line inside a branch is indented, and all of them by the same amount. Never mix tabs and spaces in one file.