我正在为项目创建聊天机器人时,如何再次 运行 一个函数?

How to Run a function again i'm creating a chatbot for project?

def chatbot(n):
     if n=="ARE U REAL?" or n=="are u real?" or n=="are you real" or n=="are you real" or n=="Are you real?" or n=="are u real":
         print("BOT: YES")
     elif n=="What's your name?" or n=='what is your name?' or n=='whats your name?' or n=='whats your name':
         print("BOT: My name is ChatBot :)")
     elif n=="":
         print("Ask something")
     else:
         print("BOT: Sorry :( I can't respond to that,Try asking another question.")
print("BOT: HEY IM CHATBOT MAY I KNOW YOUR NAME?")
a=input('YOU:')
print("BOT: Hi",a.upper())
print("BOT: ASK ME SOMETHING :)")
n=input("YOU:").lower()
#PRINT("BOT: ASK ME AGAIN") 
#N=INPUT("YOU:")SHOULD BE DONE AFTER THE ABOVE ONE HAS COMPLETED
chatbot(n)

我想要一个会话型聊天机器人来响应并轻松检查该响应。我是初学者,我希望代码简单。

使用 while 循环

def chatbot(n):
    if n=="ARE U REAL?" or n=="are u real?" or n=="are you real" or n=="are you real" or n=="Are you real?" or n=="are u real":
        print("BOT: YES")
    elif n=="What's your name?" or n=='what is your name?' or n=='whats your name?' or n=='whats your name':
        print("BOT: My name is ChatBot :)")
    elif n=="":
        print("Ask something")
    else:
        print("BOT: Sorry :( I can't respond to that,Try asking another question.")
print("BOT: HEY IM CHATBOT MAY I KNOW YOUR NAME?")
a=input('YOU:')
print("BOT: Hi",a.upper())

while True:
    print("BOT: ASK ME SOMETHING :)")
    n=input("YOU:").lower()
    if n != 'q':
        chatbot(n)
    else:
        print("BOT: BYE :)")
        break

它将一直重复,直到您输入 q