它总是给我第一次出现时的.index()
。我希望索引与列表中的位置相等。例如,This word appears in the places, 0,4
。如果用户键入chicken,那么这将是输出。你知道吗
dlist = ["chicken","potato","python","hammer","chicken","potato","hammer","hammer","potato"]
x=None
while x != "":
print ("\nPush enter to exit")
x = input("\nGive me a word from this list: Chicken, Potato, Python, or Hammer")
y = x.lower()
if y in dlist:
count = dlist.count(y)
index = dlist.index(y)
print ("\nThis word appears",count,"times.")
print ("\nThis word appears in the places",index)
elif y=="":
print ("\nGood Bye")
else:
print ("\nInvalid Word or Number")
沿着这些思路应该可以做到:
在您的示例中给出了列表
[3, 6, 7]
。。。你知道吗你可以用
而不是
相关问题 更多 >
编程相关推荐