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.
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.
A zombie lurches out of the darkness! and then
Prepare to fight., on two lines, to tell the player what they have run
into.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.
Which weapon do you want to use?
1, that is all: the weapon is one they read off the list.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.zombie_weakness.
You beat the zombie!The zombie beat you.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.
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(...).
| 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 datasweets[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) |
Make sure that you check for the following things:
zombie_weakness variable are spelled and typed exactly as
they are given above.int(), or it is text and never
equals 1.==) to compare the weapon with
zombie_weakness. A single = stores data in a variable.2.