几乎是标题。编写了一些代码,但我不知道它有什么问题,因为它无法运行。我不知道它是否接近正确。该程序是Mac和Cheese程序,用户可以在小,中和大之间进行选择,并可以添加浇头。它必须吐出打顶成本,基本成本和总成本(含税)。我想我已经接近了,但是我对整个编程工作还是很新鲜的,所以请帮助一个家伙。 :)
#Lab 8 Mac and Cheese Program
#This program calculates the cost of ordered mac and cheese
#Date: 10/10/19
#Welcome Message
print ("Thank you for your purchase! This program will calculate the total cost of your order.")
print('-'*65)
print()
#Declare Variables
small = 4.00
medium = 5.00
large = 6.00
bacon = 1.50
grilled_onions = 1.00
grilled_chicken = 2.50
sloppy_joe = 2.50
lobster = 5.00
def mainMenu():
print("1. Small $4.00")
print("2. Medium $5.00")
print("3. Large $6.00")
selection = int(input("What size Mac and Cheese would you like? Choose a number. ")
if selection == "1":
small()
elif selection == "2":
medium()
elif selection == "3":
large()
else:
print("Enter a valid selection" )
mainMenu()
def small():
small = 4.00
print("You have ordered a small Mac and Cheese. ")
toppings = str(input("Choose your toppings: ")
def menu():
print("1. Bacon $1.50 ")
print("2. Grilled Onions $1.00 ")
print("3. Grilled Chicken $2.50 ")
print("4. Sloppy Joe Meat $2.50 ")
print("5. Lobster $5.00 ")
print("6. No toppings ")
choice = int(input("Enter the number for the topping you want. ")
if choice == "1":
print("You have added Bacon to your order. ")
print("That will add 1.50 to the cost of your order. ")
more_toppings = str(input("Would you like any more toppings?" )
if more_toppings == "Yes":
menu()
if more_toppings == "No":
continue
else:
print("Invalid input, returning to toppings menu. ")
menu()
elif choice == "2":
print("You have added Grilled Onions to your order. ")
print("That will add 1.00 to the cost of your order. ")
more_toppings = str(input("Would you like any more toppings?" )
if more_toppings == "Yes":
menu()
if more_toppings == "No":
continue
else:
print("Invalid input, returning to toppings menu. ")
menu()
elif choice == "3":
print("You have added Grilled Chicken to your order. ")
print("That will add 2.50 to the cost of your order. ")
more_toppings = str(input("Would you like any more toppings?" )
if more_toppings == "Yes":
menu()
if more_toppings == "No":
continue
else:
print("Invalid input, returning to toppings menu. ")
menu()
elif choice == "4":
print("You have added Sloppy Joe Meat to your order. ")
print("That will add 2.50 to the cost of your order. ")
more_toppings = str(input("Would you like any more toppings?" )
if more_toppings == "Yes":
menu()
if more_toppings == "No":
continue
else:
print("Invalid input, returning to toppings menu. ")
menu()
elif choice == "5":
print("You have added Lobster to your order. ")
print("That will add 5.00 to the cost of your order. ")
more_toppings = str(input("Would you like any more toppings?" )
if more_toppings == "Yes":
menu()
if more_toppings == "No":
continue
else:
print("Invalid input, returning to toppings menu. ")
menu()
elif choice == "6":
print("You have chosen to add no toppings. ")
continue
toppings_cost = choice
print("The cost for all your toppings is" , toppings_cost)
base_price = small
print("The base price of your order is: ", base_price)
tax = 0.06
total_price = 0.06(choice + small)
print("The total cost of your order is ", total_price)
restart = input("Would you like to try another order? ")
if restart == "Yes"
mainMenu()
else:
print("Thank you for your order, have a great day!")
break
small()
def medium():
medium = 5.00
print("You have ordered a medium Mac and Cheese. ")
toppings = str(input("Choose your toppings: ")
def menu():
print("1. Bacon $1.50 ")
print("2. Grilled Onions $1.00 ")
print("3. Grilled Chicken $2.50 ")
print("4. Sloppy Joe Meat $2.50 ")
print("5. Lobster $5.00 ")
print("6. No toppings ")
choice = int(input("Enter the number for the topping you want. ")
if choice == "1":
print("You have added Bacon to your order. ")
print("That will add 1.50 to the cost of your order. ")
more_toppings = str(input("Would you like any more toppings?" )
if more_toppings == "Yes":
menu()
if more_toppings == "No":
continue
else:
print("Invalid input, returning to toppings menu. ")
menu()
elif choice == "2":
print("You have added Grilled Onions to your order. ")
print("That will add 1.00 to the cost of your order. ")
more_toppings = str(input("Would you like any more toppings?" )
if more_toppings == "Yes":
menu()
if more_toppings == "No":
continue
else:
print("Invalid input, returning to toppings menu. ")
menu()
elif choice == "3":
print("You have added Grilled Chicken to your order. ")
print("That will add 2.50 to the cost of your order. ")
more_toppings = str(input("Would you like any more toppings?" )
if more_toppings == "Yes":
menu()
if more_toppings == "No":
continue
else:
print("Invalid input, returning to toppings menu. ")
menu()
elif choice == "4":
print("You have added Sloppy Joe Meat to your order. ")
print("That will add 2.50 to the cost of your order. ")
more_toppings = str(input("Would you like any more toppings?" )
if more_toppings == "Yes":
menu()
if more_toppings == "No":
continue
else:
print("Invalid input, returning to toppings menu. ")
menu()
elif choice == "5":
print("You have added Lobster to your order. ")
print("That will add 5.00 to the cost of your order. ")
more_toppings = str(input("Would you like any more toppings?" )
if more_toppings == "Yes":
menu()
if more_toppings == "No":
continue
else:
print("Invalid input, returning to toppings menu. ")
menu()
elif choice == "6":
print("You have chosen to add no toppings. ")
continue
toppings_cost = choice
print("The cost for all your toppings is" , toppings_cost)
base_price = medium
print("The base price of your order is: ", base_price)
tax = 0.06
total_price = 0.06(choice + medium)
print("The total cost of your order is ", total_price)
restart = input("Would you like to try another order? ")
if restart == "Yes"
mainMenu()
else:
print("Thank you for your order, have a great day!")
break
medium()
def large():
large = 6.00
print("You have ordered a large Mac and Cheese. ")
toppings = str(input("Choose your toppings: ")
def menu():
print("1. Bacon $1.50 ")
print("2. Grilled Onions $1.00 ")
print("3. Grilled Chicken $2.50 ")
print("4. Sloppy Joe Meat $2.50 ")
print("5. Lobster $5.00 ")
print("6. No toppings ")
choice = int(input("Enter the number for the topping you want. ")
if choice == 1:
print("You have added Bacon to your order. ")
print("That will add 1.50 to the cost of your order. ")
more_toppings = str(input("Would you like any more toppings?" )
if more_toppings == "Yes":
menu()
if more_toppings == "No":
continue
else:
print("Invalid input, returning to toppings menu. ")
menu()
elif choice == "2":
print("You have added Grilled Onions to your order. ")
print("That will add 1.00 to the cost of your order. ")
more_toppings = str(input("Would you like any more toppings?" )
if more_toppings == "Yes":
menu()
if more_toppings == "No":
continue
else:
print("Invalid input, returning to toppings menu. ")
menu()
elif choice == "3":
print("You have added Grilled Chicken to your order. ")
print("That will add 2.50 to the cost of your order. ")
more_toppings = str(input("Would you like any more toppings?" )
if more_toppings == "Yes":
menu()
if more_toppings == "No":
continue
else:
print("Invalid input, returning to toppings menu. ")
menu()
elif choice == "4":
print("You have added Sloppy Joe Meat to your order. ")
print("That will add 2.50 to the cost of your order. ")
more_toppings = str(input("Would you like any more toppings?" )
if more_toppings == "Yes":
menu()
if more_toppings == "No":
continue
else:
print("Invalid input, returning to toppings menu. ")
menu()
elif choice == "5":
print("You have added Lobster to your order. ")
print("That will add 5.00 to the cost of your order. ")
more_toppings = str(input("Would you like any more toppings?" )
if more_toppings == "Yes":
menu()
if more_toppings == "No":
continue
else:
print("Invalid input, returning to toppings menu. ")
menu()
elif choice == "6":
print("You have chosen to add no toppings. ")
continue
toppings_cost = choice
print("The cost for all your toppings is" , toppings_cost)
base_price = large
print("The base price of your order is: ", base_price)
tax = 0.06
total_price = 0.06(choice + large)
print("The total cost of your order is ", total_price)
restart = input("Would you like to try another order? ")
if restart == "Yes"
mainMenu()
else:
print("Thank you for your order, have a great day!")
break
large()
mainMenu()
您可能会发现从精简程序的版本开始并使它正常工作会很有帮助。只是“小”。同样,对于每种尺寸,“ def menu()”函数似乎都重复执行。如果只有一个更通用的“ def menu()”,您可能会发现使用/调试更容易。最后,您可能需要在处理过程中注意“整数与字符串”。希望可以帮助解决问题。