Climate Quest - Task 9
Objectives
- Define what a list is in Python and explain its usefulness in storing and managing collections of data.
- Maintain a list of visited locations for the game
- Add a simple inventory system to the game
Task Overview:
In this homework, you will enhance the "Climate Quest" project by incorporating lists to manage collections of data such as locations visited and resources collected during the game.
Instructions:
-
Create Lists to Store Data:
- Use lists to store player choices, environmental health changes, and resources collected.
-
Retrieve Elements from Lists:
- Retrieve elements from the lists using positive and negative indices.
-
Iterate Over Lists:
- Use
for
loops to iterate over the elements of the lists and perform actions based on the elements.
- Use
-
List Operations:
- Use list operations like
append()
,insert()
,remove()
, andclear()
to manage the lists.
- Use list operations like
-
Check for Item Presence:
- Use the
in
keyword to check if an item is present in a list.
- Use the
-
Get Item Index:
- Use the
index()
method to get the position of an item in a list.
- Use the
Detailed Steps
Using the following code, with highlighted questions, complete the code as required by the question.
Additional Challenge 1
The user visits a number of locations, and these are presented 'long-hand' to the user in a menu that has a number of print
statements:
Using iteration, a list of locations and the in
operator, modify this function to present the menu of locations using the locations defined in the list.
Additional Challenge 2
At the moment the user can visit a location more than once. Using the list of visited_locations
how can we ensure the user only visits the location once and once only?
There will be a number of possible solutions here, e.g.
- Following on from the previous challenge, the menu ONLY displays those locations that have not been visited by the user
- The menu choice functionality checks against the list of
visited_locations
and only proceeds when the user selects a location that has not yet been visited.