嗨,我有一个学校项目,要求我编写一个程序,询问用户的详细信息,然后询问他们想要多大尺寸的比萨饼,以及需要多少配料。然后它会问他们是否想要另一个比萨饼。它会重复这个过程,直到他们说不或者他们有六个比萨饼
我真的不知道如何解释我的问题,但我不知道如何循环代码,所以它会要求另一个比萨饼,每个比萨饼都有不同的大小和数量的配料。我也不知道该怎么打印。 对不起,如果这是要求很多或它的混乱理解或如果代码只是痛苦的看啊哈
提前谢谢
CustomerName = input("Please input the customers name: ")
CustomerAddress = input("Please input the customers address: ")
CustomerNumber = input("Please input the customers number: ")
while True:
PizzaSize = input("Please input pizza size, Small/Medium/Large: ")
try:
PizzaSize = str(PizzaSize)
if PizzaSize == "Small" or "Medium" or "Large":
break
else:
print("Size not recognized")
except:
print("Invalid input")
if PizzaSize == "Small":
SizeCost = 3.25
elif PizzaSize == "Medium":
SizeCost = 5.50
elif PizzaSize == "Large":
SizeCost = 7.15
print(SizeCost)
while True:
ExtraToppings = input("Any extra toppings, 0/1/2/3/4+ ? ")
try:
ExtraToppings = float(ExtraToppings)
if ExtraToppings >= 0 and ExtraToppings <= 4:
break
else:
print("Please insert a number over 0")
except:
print("Input not recognised")
if ExtraToppings == 1:
ToppingCost = 0.75
elif ExtraToppings == 2:
ToppingCost = 1.35
elif ExtraToppings == 3:
ToppingCost = 2.00
elif ExtraToppings >= 4:
ToppingCost = 2.50
else:
print("Number not recognized")
print(ToppingCost)
``
首先,您应该将第二个while循环中的代码放在第一个while循环中。不需要两个while-true循环。而不是
放
您可以这样修改代码。我想你可以用字典简单地写出你的条件句。试试这个
相关问题 更多 >
编程相关推荐