7 Creating functions: Get the order and print it

 

In this chapter

  • Erik creates the actual functions to get and print orders
  • Erik uses a dictionary to store and print a customer’s order
  • Erik’s program now works as planned!
  • Erik and Simon plan to write a function to save orders

“Yesterday, we created the main menu, right?” Simon began his conversation with Erik. “We even tested the main menu’s functionality.”

“Yes, but it didn’t do anything useful,” Erik said.

“Right!” Simon said. “Remember, we talked about the ‘top-down’ approach? We created empty functions just to test the main menu. Now it’s time to make them do something real. Open your Python file where we created menus from files. It’s called menu_files.py.”

Erik opened that file, and now he had two tabs in his editor: one with the main_menu.py file and another with the menu_files.py file.

“Switch to the main_menu.py file, and let’s look at which functions we have to write there,” Simon said. “There are three functions: get_order(), print_order(), and save_order(). Let’s begin with get_order(). Where is our diagram?”

“Let’s start with get_name. What do we do here?” Simon asked.

“We just ask ‘What’s your name?’,” Erik answered.

“Right, and then?”

“And then we save it in a variable, like name.”

What are your choices?

Print it!

New things you have learned today

Code for this chapter