尝试查找输入的len()时遇到TypeError。我尝试将其分配给另一个变量,以免感到高兴。以后有什么问题吗?谢谢!
"""Listo_matic Function"""
items = ['cat', 'goat', 'cat']
def listo_matic(user):
action = ""
num = 0
if len(user) == 0:
items.pop()
action += "popped"
num += 1
print(items)
elif user in items:
items.remove(user)
action += "removed"
num += 1
print (items)
elif user not in items:
items.append(user)
action += "appended"
num += 1
print(items)
return (str(num)+"instance of"+ user+ action+ "from the list")
while len(list(items)) != 0:
print("Look at all of the animals:" + str(items))
user = input("enter the name of an animal: ").lower
if user == quit:
print("Goodbye!")
break
else:
listo_matic(user)
print("Program terminated: Goodbye!")
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-14-42f81f2dfb7d> in <module>()
32 break
33 else:
---> 34 listo_matic(user)
35 print("Program terminated: Goodbye!")
36
<ipython-input-14-42f81f2dfb7d> in listo_matic(user)
5 action=""
6 num=0
----> 7 if len(user) == 0:
8 items.pop()
9 action+= "popped"
TypeError:类型为“ builtin_function_or_method”的对象没有len()