我正在将这段代码用于我需要为朋友设计的小程序.问题是无法让它发挥作用.
我正在设计一个使用蔬菜和水果清单的程序.例如我的列表是:
smallist = [["apple", 2], ["banana", 3], ["strawberry",1]] item = input("Please give the name of the fruit\n\n") smallist.index(item) print (smallist)
问题是当我尝试找到让我们说苹果的索引时.我只是说苹果不存在.
smallist.index(item) ValueError: 'apple' is not in list
我无法弄清楚为什么它不会向我展示苹果的价值,在这种情况下它将是2