【发布时间】:2019-06-16 01:36:23
【问题描述】:
所以基本上我只是觉得我的代码并没有真正到达任何地方。我对清单和其他东西有疑问,我需要这个上学。我的老师并没有真正教过,这是他们迄今为止“教”给我们的关于列表数组的内容,但我并不真正理解它。另外,我不断收到以下错误:
TypeError: append() takes exactly 2 arguments (1 given) on line 31
我没问题,打印结果正常。我在这里拿出我的整个菜单,然后粘贴到我出现问题的地方。这是实际工作的部分:
print "[Welcome to Python Cafe!]"
print ('\n')
print "1) Menu and Order"
print "2) Exit"
choice=input("What would you like to do? ")
print ('\n')
if choice == "1":
print "-T H E M E N U-"
print " DRINKS "
print "1. Coffee: $2.50"
print "2. Hot Cocoa: $2.30"
print "3. Tea: $1.50"
print " FOOD "
print "4. Bagel: $1.50"
print "5. Donut: $1.00"
print "6. Muffin: $1.50"
主要问题出在while 语句和if 语句中,以及它是如何实现的
最后不打印我的订单。我已经尝试更改我的代码,例如:if order == "coffee": 改为 if order == "1":,这样我可以让它更容易,这样用户就不必输入整个单词?我还尝试取出tot=tot+... 只是为了看看。我不知道,我的老师只是告诉我们这样做,但我认为这种格式不太正确。
if choice == "1":
print ('\n')
food=[]
order=0
while order != "done":
order=input("What's your order? ")
if order == "coffee":
list.append("coffee")
tot=tot+2.50
else:
if order == "hot cocoa":
list.append("hotcocoa")
tot=tot+2.30
if order == "tea":
list.append("tea")
tot=tot+1.50
if order == "bagel":
list.append("bagel")
tot=tot+1.50
if order == "donut":
list.append("donut")
tot=tot+1.00
if order == "muffin":
list.append("muffin")
tot=tot+1.50
print ('\n')
print "Here's your final order:"
for item in food:
print(order)
当append() 错误没有出现,并且当我将其改回代码实际上“工作”时,它只是在“完成”之后结束并且之后不打印任何内容。如果这看起来真的很混乱,我很抱歉,我只是认为整个代码是一团糟。
【问题讨论】:
-
随便输入
food.append(...)...