A function argument is information supplied inside a function call’s parentheses. The function uses that information to do its job: it might print a message, calculate a result, or work with a string. Arguments can be strings, numbers, variables, or several values at once. section 1.2 section 1.4
A call such as print("Welcome!") passes a string argument to print(). input("Please enter your name: ") passes a prompt to input(). A function may return an answer instead of printing it; store that returned value in a variable, then use or print the variable afterward. section 1.2
Arguments make one reusable function handle changing parts of a task. When code repeats, identify what stays the same and what changes; pass the changing choices, title, and prompt as arguments rather than rewriting the whole menu. section 3.0
When calling a function, keep this small checklist handy:
- Put the values the function needs between its parentheses. section 1.4
- Pass each value in the order the function expects, such as choices, then a title, then a prompt. section 3.0
- Save a returned result in a variable when the program needs it later. section 1.2 section 3.1
One menu function, three orders
The menu function receives a list of choices plus optional title and prompt text. Calling menu(drinks) uses its default title and prompt; calls for flavors and toppings supply new text. Each call returns the selected item, which is saved in drink, flavor, or topping. section 3.0
Listing 3.1 The full menu program with a function
def menu(choices, title="Erik's Menu", prompt="Choose your item: "):
print(title)
print(len(title) * "-")
i = 1
for c in choices:
print(i, c)
i = i + 1
choice = input(prompt)
answer = choices[int(choice) - 1]
return answer
drinks = ["chocolate", "coffee", "decaf"]
flavors = ["caramel", "vanilla", "peppermint", "raspberry", "plain"]
toppings = ["chocolate", "cinnamon", "caramel"]
drink = menu(drinks)
flavor = menu(flavors, "Erik's flavors", "Choose your flavor: ")
topping = menu(toppings, "Erik's toppings", "Choose your topping: ")
print("Here is your order: ")
print("Main product: ", drink)
print("Flavor: ", flavor)
print("Topping: ", topping)
print("Thanks for your order!")
This complete coffee-order program shows arguments passed to menu() and the returned selections used in the final order. section 3.0




