5.2 - Three courses
Create a program that asks the user three questions to help build a three-course meal.
- The first procedure asks if the user wants something comforting or refreshing, and displays a starter based on the answer.
- The second procedure asks if the user prefers food that is crunchy or soft, and displays a main course based on the answer.
- The third procedure asks if the user prefers sweet or savoury, and displays a dessert based on the answer.
The main program should only contain calls to the three procedures.
- Starter options:
- Comforting → Tomato Soup
- Refreshing → Mixed Salad
- Main course options:
- Crunchy → Margherita Pizza
- Soft → Tomato Pasta
- Dessert options:
- Sweet → Chocolate Cake
- Savoury → Cheese Board
Do you want something comforting or refreshing? comforting Starter: Tomato Soup. Do you prefer crunchy or soft? crunchy Main: Margherita Pizza. Do you prefer sweet or savoury? sweet Dessert: Chocolate Cake.
PROCEDURE starter()
OUTPUT "Do you want something comforting or refreshing?"
INPUT choice
IF choice = "comforting" THEN
OUTPUT "Starter: Tomato Soup."
IF choice = "refreshing" THEN
OUTPUT "Starter: Mixed Salad."
END PROCEDURE
PROCEDURE main_course()
OUTPUT "Do you prefer crunchy or soft?"
INPUT choice
IF choice = "crunchy" THEN
OUTPUT "Main: Margherita Pizza."
IF choice = "soft" THEN
OUTPUT "Main: Tomato Pasta."
END PROCEDURE
PROCEDURE dessert()
OUTPUT "Do you prefer sweet or savoury?"
INPUT choice
IF choice = "sweet" THEN
OUTPUT "Dessert: Chocolate Cake."
IF choice = "savoury" THEN
OUTPUT "Dessert: Cheese Board."
END PROCEDURE
# main program
CALL starter()
CALL main_course()
CALL dessert()
# main program starter() main_course() dessert()
def starter():
choice = input("Do you want something comforting or refreshing? ")
if choice == "comforting":
print("Starter: Tomato Soup.")
if choice == "refreshing":
print("Starter: Mixed Salad.")
def main_course():
choice = input("Do you prefer crunchy or soft? ")
if choice == "crunchy":
print("Main: Margherita Pizza.")
if choice == "soft":
print("Main: Tomato Pasta.")
def dessert():
choice = input("Do you prefer sweet or savoury? ")
if choice == "sweet":
print("Dessert: Chocolate Cake.")
if choice == "savoury":
print("Dessert: Cheese Board.")
# main program
starter()
main_course()
dessert()
# procedure to ask about the starter
def starter():
choice = input("Do you want something comforting or refreshing? ")
if choice == "comforting": # check if the user typed "comforting"
print("Starter: Tomato Soup.")
if choice == "refreshing": # check if the user typed "refreshing"
print("Starter: Mixed Salad.")
# procedure to ask about the main course
def main_course():
choice = input("Do you prefer crunchy or soft? ")
if choice == "crunchy": # check if the user typed "crunchy"
print("Main: Margherita Pizza.")
if choice == "soft": # check if the user typed "soft"
print("Main: Tomato Pasta.")
# procedure to ask about the dessert
def dessert():
choice = input("Do you prefer sweet or savoury? ")
if choice == "sweet": # check if the user typed "sweet"
print("Dessert: Chocolate Cake.")
if choice == "savoury": # check if the user typed "savoury"
print("Dessert: Cheese Board.")
# main program (only calls to the procedures)
starter()
main_course()
dessert()
Extension
Update the program to include a procedure to ask about a drink.
Do you want something comforting or refreshing? refreshing Starter: Mixed Salad. Do you prefer crunchy or soft? soft Main: Tomato Pasta. Do you prefer sweet or savoury? savoury Dessert: Cheese Board. Do you prefer hot or cold drinks? cold Drink: A glass of Juice.