2 Lists: What’s on the menu?

 

In this chapter

  • Erik starts using menus in his coffee shop
  • Erik uses Python lists for his drinks, flavors, and toppings
  • Erik uses for loops to print out his lists
  • Simon explains how computers store numbers and strings
  • Erik learns an important thing about list indices

The next day, Erik was ready to continue working on his Coffee Shop application. He remembered that Simon said something about missing products that customers might enter in the dialogue. He came to his brother and asked, “You said yesterday that customers can enter something that I don’t have in the shop. What should I do about it?”

“Remember the last time you were in a coffee shop or restaurant. How did you know what you could order?”

“They had a menu with a list of products that they have in the shop.”

“Right!” Simon said. “A menu! This is what we’re going to create today. What does a menu look like in a coffee shop?”

“It’s a list. A list of drinks like coffee, chocolate, and decaf. And a list of flavors I can add. Like caramel, mint, and others. And a list of toppings.”

“Right, lists!” Simon was very glad Erik had used that word. “Like this, right?” He quickly drafted something that looked like a menu.

“Lists are what we need! We have lists in Python—you may remember that. Lists are very useful in Python. They can contain numbers, strings, and even other lists. For example . . . ,” Simon took another piece of paper and wrote several examples.

New things you have learned today

Code for this chapter

sitemap