Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/344.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 只能串联错误,可以';我不知道该怎么办_Python_Python 3.x_Types - Fatal编程技术网

Python 只能串联错误,可以';我不知道该怎么办

Python 只能串联错误,可以';我不知道该怎么办,python,python-3.x,types,Python,Python 3.x,Types,我正在尝试为用餐者提供电子菜单服务,其中一个必需的功能是能够添加到菜单中。我在调试方面不是很在行,现在我遇到了一个错误 只能将列表(而不是字符串)连接到列表 我不知道这意味着什么,我已经尽了一切努力来消除这个错误,但它不会消失。你们能帮帮我吗 menu = (["all day breakfast large, £5.50", "all day breafast small, £3.50", "hot dog, £3.00", &quo

我正在尝试为用餐者提供电子菜单服务,其中一个必需的功能是能够添加到菜单中。我在调试方面不是很在行,现在我遇到了一个错误

只能将列表(而不是字符串)连接到列表

我不知道这意味着什么,我已经尽了一切努力来消除这个错误,但它不会消失。你们能帮帮我吗

menu = (["all day breakfast large, £5.50", "all day breafast small, £3.50", "hot dog, £3.00", "burger, £4.00", "cheese burger, £4.25", "chicken goujons, £3.50", "fries, £1.75", "salad, £2.20", "milkshake, £2.20", "soft drinks, £1.30", "still water, £0.90", "sparkling water, £0.90"])
for i in menu:
    text_file.write(i)
    

elif menu_editing == "add":
    add_item_number = (input("please enter what number you would like to add the new item. "))
    add_item_name = (input("""please enter the name of the item like this: all day breakfast large""")) 
    add_item_price = (input("please enter the price of the item you wish to add without the pound sign. "))
    menu == menu + "",add_item_name,"£"+add_item_price[add_item_number]

菜单
变量是列表吗?如果是,您应该使用
menu.append()

另外,您的输入返回了三个字符串,您想用
添加商品价格[add\u item\u number]
实现什么?根据我们掌握的少量信息,我假设您希望显示price*itemnumber?您可以这样做:

menu.append(f“{add_item_name},£{int(add_item_price)*int(add_item_number)}”)


注意
f”“
符号,它允许使用accolades引用字符串中的变量。

错误告诉您不能将
list
类型的对象与
str
类型的对象连接在一起。请您更新您的代码,以便我们了解您如何创建
菜单
?首先使用
print()
print(type(…)
查看变量中的内容。它被称为
打印调试
。然后你就会知道你试图连接什么。所显示的代码毫无意义-请在问题中包含完整的错误消息和回溯。代码的后面不能有elif(仅在之后,如果
menu==menu+“”,add_item_name,…
是一个被丢弃的元组;最后一个元素
add\u item\u price[add\u item\u number]
尝试按字符串索引字符串,这是一个错误。有许多多余的括号掩盖了事情的进展,键名未定义(
text\u file
menu\u editing
)。请参阅如何最好地帮助我们帮助您的页面。