Drop hier links of afbeeldingen om ze aan de editor toe te voegen.

In a make task you use the skills you have learned to create a program from scratch. There is no starter code: you begin with an empty editor.

You are going to write Beat the Zombie, the fight scene from a role playing game. The player meets a zombie, picks a weapon, and wins only if the weapon they picked happens to be the one thing that zombie cannot survive.

This task combines a lot of what you have learned so far, so do look back at your earlier work.

The data

So that the output can be checked automatically, the zombie and the weapons are fixed. Start your program with exactly these two lines:

weapons = ["axe", "crossbow", "flamethrower", "shotgun", "torch"]
zombie_weakness = "flamethrower"

weapons is the list of weapons the player can choose from, and zombie_weakness holds the one weapon from that list that beats this zombie.

Your task

  1. Print A zombie lurches out of the darkness! and then Prepare to fight., on two lines, to tell the player what they have run into.
  2. Print the whole list of weapons, so the player can see what is on offer.
  3. Ask the player to type 1 to use a weapon from the list, or 2 to name a weapon of their own. Ask the question with its own print, exactly as written:
    Type 1 to pick a weapon from the list, or 2 to name your own:
    

    Read the answer with a bare input() and cast it with int(). The player always types 1 or 2.

  4. Either way, ask them for the name of the weapon they want to use and store it in a new variable. Ask this question the same way, exactly as written:
    Which weapon do you want to use?
    
    • If they typed 1, that is all: the weapon is one they read off the list.
    • If they typed 2, the weapon is a new one, so add it to the end of the list and then print the whole list again, so the player can see their weapon has joined it.
  5. Compare the weapon they chose with zombie_weakness.
    • If the two are the same, print You beat the zombie!
    • Otherwise, print The zombie beat you.

The output

Both questions are printed exactly as written above. Counting them, your program prints six lines when the player types 1, and seven when they type 2, because of the second look at the list.

A whole list printed in one go comes out with its square brackets, quotes and commas, like this:

['axe', 'crossbow', 'flamethrower', 'shotgun', 'torch']

The weapon name is matched exactly as it is typed, capital letters included, so Flamethrower does not beat a zombie whose weakness is flamethrower.

Nothing stops the player from typing 2 and naming a weapon that is already in the list. A list is allowed to hold the same item twice, so it simply gets added a second time and the fight carries on as normal.

Example

Input:

1
flamethrower

Output:

A zombie lurches out of the darkness!
Prepare to fight.
['axe', 'crossbow', 'flamethrower', 'shotgun', 'torch']
Type 1 to pick a weapon from the list, or 2 to name your own:
Which weapon do you want to use?
You beat the zombie!

Input:

1
axe

Output:

A zombie lurches out of the darkness!
Prepare to fight.
['axe', 'crossbow', 'flamethrower', 'shotgun', 'torch']
Type 1 to pick a weapon from the list, or 2 to name your own:
Which weapon do you want to use?
The zombie beat you.

Input:

2
chainsaw

Output:

A zombie lurches out of the darkness!
Prepare to fight.
['axe', 'crossbow', 'flamethrower', 'shotgun', 'torch']
Type 1 to pick a weapon from the list, or 2 to name your own:
Which weapon do you want to use?
['axe', 'crossbow', 'flamethrower', 'shotgun', 'torch', 'chainsaw']
The zombie beat you.

Input:

2
flamethrower

Output:

A zombie lurches out of the darkness!
Prepare to fight.
['axe', 'crossbow', 'flamethrower', 'shotgun', 'torch']
Type 1 to pick a weapon from the list, or 2 to name your own:
Which weapon do you want to use?
['axe', 'crossbow', 'flamethrower', 'shotgun', 'torch', 'flamethrower']
You beat the zombie!

(the player names their own weapon, and picks the one that beats the zombie anyway)

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 Type 1 to pick a weapon from the list, or 2 to name your own: and Which weapon do you want to use?, 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 list and the zombie_weakness variable are spelled and typed exactly as they are given above.
  • The number the player types is wrapped in int(), or it is text and never equals 1.
  • You have used a double equals (==) to compare the weapon with zombie_weakness. A single = stores data in a variable.
  • The weapon the player names is stored in a variable of its own, not written over the list.
  • The list is only printed a second time when the player typed 2.
  • Every line inside a branch is indented, and all of them by the same amount. Never mix tabs and spaces in one file.