89.7k views
3 votes
Write a program in Python that allows the user to build a custom made crepe using only the concepts covered in this course to date. The program needs to ask the user what fillings they would like. As the user selects fillings the price of these fillings will accumulate until the user enters Q to quit the loop the selecting fillings. The base price of a crepe is $2. The choice of fillings and their cost is up to you. Make sure you include at least 3 different fillings. The program also needs to ask the user how many crepes they wish to purchase and calculate the total for the order. The output needs to include the price of the fillings and the total price as separate outputs. When you write the program, you will need to demonstrate your knowledge of modular programming, Your program MUST contain the following: - main0 - One function that demonstrates the usage of parameters. - One function that demonstrates how to return a value. - Call statements in main that call your other functions. Properly demonstrating how to use arguments. - No less than 3 functions. One of these can be main. - The choice of at least 3 fillings. - appropriate and complete output and input statements. A failure to follow these specifications will result in a drastic reduction in points. Using concepts not covered in this course to date will also result in a drastic reduction in points. Make sure your program includes, at the top, the decomposition for your program. Additionally make sure your have readable input and output statements.

1 Answer

5 votes

Final answer:

The Python program allows the user to choose fillings for a crepe, calculates the cost of the fillings, and the total cost for the specified number of crepes. It demonstrates modular programming with a main function and two additional functions, one using parameters and the other returning a value.

Step-by-step explanation:

To write a Python program that allows a user to build a custom made crepe, you need to apply the basic concepts of programming such as loops, functions, I/O operations, and simple arithmetic operations. The following program incorporates these principles:

Python Program for Crepe Order System

# Define the base price of a crepe
BASE_PRICE = 2.0

# Define fillings and their prices
FILLINGS_PRICES = {
'Cheese': 0.5,
'Ham': 0.7,
'Chocolate': 0.6
}

# Function to display filling options and get choice
def choose_fillings():
total_fillings_price = 0
while True:
print("Choose a filling (or Q to quit):")
for filling, price in FILLINGS_PRICES.items():
print(f"{filling} (${price})")
choice = input("What filling would you like? ")
if choice == 'Q':
break
if choice in FILLINGS_PRICES:
total_fillings_price += FILLINGS_PRICES[choice]
else:
print("Invalid choice. Please try again.")
return total_fillings_price

# Function to calculate the total price
def calculate_total(crepes_count, fillings_cost):
return crepes_count * (BASE_PRICE + fillings_cost)

# Main function
def main():
print("Welcome to the Crepe Maker!")
fillings_cost = choose_fillings()
print(f"The price for fillings is: $({fillings_cost:.2f})")
crepes_count = int(input("How many crepes would you like to purchase? "))
total_cost = calculate_total(crepes_count, fillings_cost)
print(f"The total price is: ${total_cost:.2f}")

if __name__ == '__main__':
main()

User ArtemSBulgakov
by
7.8k points