Limiting items in a virtual backpack
To make sure that we only add four items to each virtual backpack, we are using another for
loop (inside our first for
loop). The inside loop says for item in range(4)
. This means for each item out of four items, do all the things in the loop. In our backpack loop, this means that we will enter items 0, 1, 2, and 3 into the backpack using the raw_input()
function.
In the players[i]backpack
dictionary, we append (add) items to the list inside of the backpack by using append(backpack_item)
. Because we want four items, our for
loop runs four times after asking for the name and items of the player. When this backpack_item
code finishes running, the entire player loop will begin again, asking for the name and items for the second player. In this process, we get the information we need to fill out the player profiles that are stored in the dictionaries of player 1
and player 2
:
To review, when you run your code, you should expect to see the following:
Create a...