ninja.py
Introduction to Lists
Swipe to show menu
Python lists are like containers that can hold different items. You can create a list by enclosing items in square brackets []:
list_ = ["cat", "dog", "chicken", "monkey"]
In the Ninja Game, you can interact with the list using the following methods:
pick_to_inventory(index): picks up an item and places it in the inventory at the specifiedindex, or adds it to the end of the list (or the first element if the list is empty) if noindexis provided;put_from_inventory(index): takes an item from the inventory byindexand places it on the map. If noindexis provided, it takes the last item.
Here is an example where the Ninja collects 2 animals into the inventory and then places the first element back on the map.
Note
In Python, counting starts from 0.
Note
In this course, you do not need to define lists yourself β they are already built into the code logic.
ninja.py
When you run the code on the map, you will see a purple bar at the top β this is your inventory.
Swipe to start coding
Solution
Explore other courses in Catalog
Thanks for your feedback!
ninja.py
Ask AI
Ask AI
Ask anything or try one of the suggested questions to begin our chat