Here’s a simple Python program that allows users to create a Peanut Butter and Grape Jelly sandwich by selecting different options for bread, peanut butter, and jelly. The program will confirm the user's choices before finalizing the sandwich.
def welcome():
print("Welcome to the Peanut Butter and Grape Jelly Sandwich Maker!")
def choose_bread():
print("Please choose your bread:")
breads = ["White Bread", "Whole Wheat Bread", "Sourdough Bread"]
for index, bread in enumerate(breads, start=1):
print(f"{index}. {bread}")
choice = int(input("Enter the number of your choice: "))
return breads[choice - 1]
def choose_peanut_butter():
print("Please choose your peanut butter:")
peanut_butters = ["Creamy Peanut Butter", "Crunchy Peanut Butter", "Natural Peanut Butter"]
for index, pb in enumerate(peanut_butters, start=1):
print(f"{index}. {pb}")
choice = int(input("Enter the number of your choice: "))
return peanut_butters[choice - 1]
def choose_jelly():
print("Please choose your grape jelly:")
jellies = ["Concord Grape Jelly", "Natural Grape Jelly", "Homemade Grape Jam"]
for index, jelly in enumerate(jellies, start=1):
print(f"{index}. {jelly}")
choice = int(input("Enter the number of your choice: "))
return jellies[choice - 1]
def confirm_sandwich(bread, peanut_butter, jelly):
print("\nYour sandwich configuration:")
print(f"Bread: {bread}")
print(f"Peanut Butter: {peanut_butter}")
print(f"Grape Jelly: {jelly}")
confirmation = input("Is all this information correct? (yes/no): ").strip().lower()
return confirmation == 'yes'
def make_sandwich():
welcome()
bread = choose_bread()
peanut_butter = choose_peanut_butter()
jelly = choose_jelly()
if confirm_sandwich(bread, peanut_butter, jelly):
print("Great! Your sandwich is being made...")
print("Enjoy your Peanut Butter and Grape Jelly sandwich!")
else:
print("Let's start over!")
make_sandwich()
if __name__ == "__main__":
make_sandwich()
Explanation of the Program:
- Welcome Function: Welcomes the user to the application.
- Choose Functions: Individual functions allow the user to select their preferred bread, peanut butter, and jelly, displaying a numbered list for easier selection.
- Confirm Function: Displays the user's selections for confirmation. The user can accept or reject their choices.
- Make Sandwich Function: Orchestrates the flow of the program, calling each function in order. If the user confirms their choices, the program displays a message indicating that the sandwich is being made. If not, it restarts the process.
- Main Block: The
if __name__ == "__main__":
block ensures that the program runs when executed directly.
Feel free to modify the options or the messages to customize the user experience further!