目前我正在上一门编程课程,我被困在这个问题上。当我点击提交时,它说有一个无限循环,我已经测试了几个小时并结束了,似乎找不到它。
import re
text = ""
print("Hello, my name is Eliza. What would you like to talk about?")
while text != "go away":
if text != "go away":
text = input()
text = text.lower()
if re.search(r"\bfeel\b", text) is not None:
print("Do you often feel that way?")
elif re.search(r"\bi am\b", text) is not None:
m = str(re.findall('i am\w* (\w+)',text))
m = re.sub('[\'\]\[]', '', m)
print("How long have you been",m+"?")
elif "you" in text:
if "me" in text:
m = str(re.findall('you\w* (\w.*)',text))
m = m.replace("me","you")
m = re.sub('[\'?\]\[]', '', m)
print("What makes you think I",m+"?")
else:
print("Please go on")
elif text == "go away":
text = "go away"
break
else:
print("Please go on")
else:
text = "go away"
print("I hope I have helped you!")
这是它给我的错误。
你的程序产生了太多的输出!这可能是因为您的代码中存在无限循环。