Chapter 7. What's in Your Backpack?

In Chapter 6, Working with Data – Lists and Dictionaries, we explored how to store, retrieve, and change data using lists and dictionaries in Python. In this chapter, we will build a two player game called What's in Your Backpack? This game will require us to review all of the skills we have learned since the beginning of this book. We use our skills to make loops, ask for information from the user with the raw_input() function, and then store this information in lists or dictionaries.

Be prepared to also learn some new skills that might seem complicated. We will try something called nesting or putting one thing inside another. With nesting lists and dictionaries, we have more flexible data storage. Using this new nesting skill with the other skills we have learned, we will create a game that can be played by two users or adjusted to be played by many users.

Setting up our coding environment

This chapter will have the largest amount of code that we have written. Since we are going to do a lot of coding, it is important to have our tools ready so that we can test run our code frequently and save often.

Tip

Testing and saving the code as you go along allows you to try new things and correct any mistakes!

To work on this game, it is recommended that you have your Python shell open so that you can test out small lines of code before putting them into your text editor.

Also, you will need to open your text editor (JEdit in Mac/Linux or Notepad++ in Windows), and make a new file called backpack.py. Finally, you will need to open your command prompt so that you can run the backpack.py program to test it out while you are writing the game. Hopefully, you are feeling more at ease with the different tools that are used to create a computer program. If you do not recall how to open the Python shell or command prompt, refer to Chapter 1, Welcome! Let's Get Started.

If you have questions or want to know more about the Python shell, command prompt, or text editor that you are using on your computer, perform an Internet search and learn more about the tools.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.117.72.224