【发布时间】:2016-03-09 22:36:37
【问题描述】:
我有一个用 Python 编写的小程序。除了基于命令行之外,它应该像 Siri 一样与您交谈。它会问你今天过得怎么样,当你说得好时,它应该从 5 个好的回答中选出 1 个对你说,但我不断收到递归错误,这是我的代码
def nice5():
print ("Well Thats Good!")
time.sleep(2)
randsub(2)
def nice4():
print ("Great!")
time.sleep(2)
randsub()
def nice3():
print ("Thats Good!")
time.sleep(2)
randsub()
def nice2():
print ("Cool I am glad to hear that!")
time.sleep(2)
randsub()
def nice1():
print ("Thats Good! ")
time.sleep(2)
randsub()
def nicerand():
randnices = [nice1 , nice2 , nice3 , nice4 , nice5]
randnice = random.choice(randnices)
nicerand()
def p1checkChoice():
if choice == "Good":
nicerand()
if choice == "good":
nicerand()
if choice == "GOOD":
nicerand()
def greeting():
clearscr()
name = input("Hello What is your name: ")
clearscr()
print ("Hello " + name)
time.sleep(2)
clearscr()
print ("Allow me to introduce myself")
time.sleep(2)
clearscr()
print ("My name is Chatbot")
time.sleep(2)
clearscr()
choice = input("How has your day been: ")
global choice
p1checkChoice()
greeting()
【问题讨论】:
-
能否提供准确的错误信息和
Randnices的定义 -
RecursionError: 调用 Python 对象时超出最大递归深度
-
Global choice大写G?请提供您使用的确切来源。
标签: python-3.x