【发布时间】:2014-06-02 15:40:35
【问题描述】:
我必须使用 python 编写一个披萨订购系统。在我的程序的一部分中,我必须询问用户想要多少比萨饼,然后他们会从比萨饼列表中选择他们想要什么样的比萨饼,他们必须选择不同的比萨饼。我想使用 for 循环重复输入问题的次数与用户说出他们想要多少比萨饼的输入一样多。
到目前为止,我的代码有两部分。我的第一个输入问题:
pizza_number= int(input("How many Pizzas do you want? (MAX 5): "))
还有比萨饼列表:
PIZZA_LIST=["Tandoori chicken: $8.50", "Prawn: $8.50", "Ham and cheese: $8.50", "Pepperoni: $8.50", "Hawaiian: $8.50","Beef and onion: $8.50","Meat lovers: $8.50", "Satay chicken: $13.50", "Apricot chicken: $13.50", "Supreme cheese:13.50", "Italian beef: $13.50", "Mediterraneo: $13.50"]
for index in range(0, len(PIZZA_LIST)):
print(index, PIZZA_LIST[index])
菜单将显示给用户,每个比萨饼旁边都会有一个数字,当他们说出想要的比萨饼时,他们会输入与比萨饼相对应的数字(例如 1 = 对虾,2= 火腿和奶酪等)
我将如何编写 for 循环?
【问题讨论】:
标签: python list for-loop input