2 Lists: What’s on the menu?

 

In this chapter

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

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 can order?"

"They had a menu with a list of products that they have in this shop."

"Right!" Simon said. "A menu! This is what we are going to create today. How does a menu look like in a coffee shop?"

"It’s a list. A list of main drinks like coffee, chocolate, 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 the Erik used that word. "Like this, right?" and he quickly drafted something that looked like a menu.

Coffee shop menu

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

List examples

2.1 New things you have learned today

2.2 Code for this chapter

sitemap