我目前正在尝试用python编写一个代码,如果您的回答在可能的答案列表中,那么该代码将对您做出响应。程序示例如下。
def responce():
greetings = ["Hello","Hi","Nice to see you!","Greetings","How's it going?","How are you doing?","What's new?","How's your day going?","Hey!"]
print("\n")
reply = input(": ")
lenrep = len(reply)
tempstore = []
for i in range(0,lenrep):
tempstore.append(i)
z = 0
while z < 9:
tempgreet = greetings[z]
if tempstore.upper() == tempgreet.upper():
reply = ""
tempstore = []
temprandno = random.randint(0,2)
addon = ["what do you want to know?", "what do you want to talk about?", " "]
addontext = addon[temprandno]
text(greet(), + " " + addontext)
z += 1
if i == " ":
tempstore = []
现在我的问题是,为什么会出现错误
AttributeError: list object has no attribute 'upper'
有没有办法修正我的程序使之生效?
谢谢你的回复。
提示:
将问候语列表中的所有字符串转换为大写字母,并将表达式
允许您决定
reply
是否在当前列表中。您可以在if
语句中使用它:相关问题 更多 >
编程相关推荐