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 ...

Get Python Projects for Kids now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.