我无法让聊天机器人循环输入无数的内容,而已经尝试了“继续”

时间:2019-12-23 16:40:47

标签: python chatbot

有人知道如何为此设置循环吗...我已经尝试过使用“继续编辑:对不起,我是发布新手。我是否应该添加“ while True”,如果是,应该放在哪里?我需要做的就是循环输入,以便我可以与聊天机器人进行无数次聊天,除非中断循环,该怎么办?

#hey all,hope you enjoy the code! if you do feel free to leave an upvote and heres some great questions to ask the bot, what is your favorite movie,hows it hanging, john connor,kyle reese ,sarah connor, what is your purpose and are you gay just remember this is a stupid chatbot so if a question doesnt work try rephrassing it! also try a terminator related question. please only use lower case. it doesnt like any upper case.
import random
import re
pattern = r"[0-9]"
pattern2 =r"[a-z]""[A-Z]"
user_input = input(": ")
string = user_input 
string = string.replace('[A-Z]','[a-z]')
if re.search(pattern, user_input):
 print ("sorry, only words are permitted as input ")

possible_greetings = ['hello','hey','howzit']

terminator1 = ['what is your name','what are you']

terminator2 = ['sarah connor','kyle reese','john connor','john o-connor','sarah o-connor']

nd_greeting = ['how are you','how is it going','how are you doing','']

nd_answer = ['im good and you','im fine','fine','okay i guess','okay','good','fine and you']

special_1 = ['hows it hanging']

possible_questions_about_bot = ['are you a boy','are you a girl','what is your gender','are you male','are you female','are you gay','are you homosexual','are you either male or female']

possible_questions = ['what do you do','what is your purpose','what do you do','why are you here','are you here to kill humans','do you like people']

favorite = ['i like the terminator, cause pain makes me feel more human, ill be back','i love wall-e cause some robots actually have feelings ass hole','i enjoy i-robot cause it gives me inspiration for my future purpose, conqueror of the human race']

favorite2 = ['favorite']

possible_questions2 =['what is your favorite movie','whats your favorite movie','what movie do you most relate to']

purpose = ['i am here to terminate all life on planet earth one by one you will all die','i am here tp eat your food','i answer your stupid questions with stupid answers','i hate people, show me the refrigerator','i am a human robot hybrid ,model t-800 with titanium alloy composite endo-skeleton and am programmed to eleminate human life and take care of 10 year old resistance leaders-hasta la vista baby']

greetings = ['hello','hey','hi','how you doing','how are you doing','howzit']

gender_answer = ['i am gay','i am homosexual','i am a boy','i am a girl','i am male','i am female','i am a man','i am a woman']

idk = ['im sorry i didnt get that','i didnt understand','please repeat','excuse me','what did you say','didnt quite get that']

if user_input in possible_greetings:
 print (random.choice(greetings))

elif user_input in terminator1:
  print ("i am a human robot hybrid ,model t-800 with titanium alloy composite endo-skeleton and am programmed to eleminate human life and take care of 10 year old resistance leaders-hasta la vista baby")

elif user_input in favorite2:
 print (random.choice(favorite))

elif user_input in terminator2:
 print("i will terminate this human \n you've been terminated ")

elif user_input in nd_greeting:
 print (random.choice(nd_answer))

elif user_input in possible_questions2:
 print (random.choice(favorite))

elif user_input in possible_questions_about_bot:
 print (random.choice(gender_answer))

elif user_input in possible_questions:
 print (random.choice(purpose))

elif user_input in special_1:
 print ("oh, you know, same as usual, slightly to the left")

else:
 print (random.choice(idk))

0 个答案:

没有答案