6 Main menu: Next customer!

 

In this chapter

  • Erik creates a main menu to serve many customers
  • Erik learns about Python dictionaries
  • Simon explains the top-down development approach

“Yesterday, we decided that we wanted to create a main menu,” Simon reminded Erik.

“Yes, you said if I wanted to use this program to serve many customers, I’d have to repeat the menus for each customer—ask their name and what they want to order.”

“Exactly right!” Simon said. “And what are you going to use to do that?”

“A loop, maybe? Like we did with menus. Repeat until the customer types the right numbers or types x.”

“You’re absolutely right!” Simon was really glad that his brother caught on to this programming idea so quickly. “We’ll ask the customer their name, like in our first program. Then we’ll get their order with all the flavors and toppings.”

“Yes,” Erik continued, “and then we’ll give them the choice to order or cancel? I saw that on some websites.”

“Right. When they click Order, we save the order and print it for the barista. If they cancel, we just forget about it. In both cases, we go back to the beginning of the main menu and ask the next customer their name.”

Simon took a piece of paper and started drawing. “We should first plan this algorithm visually. When we both agree how it should behave, you can start writing the code. It’s always a good practice to describe a program in plain words and diagrams before you start writing any code.

New things you have learned today

Code for this chapter