【发布时间】:2016-02-02 00:32:22
【问题描述】:
我正在创建一个人工智能/个人助理/聊天机器人组合。它非常适合聊天和回答我已经输入答案的问题,并且代码相当简单。
但我需要添加一种方式,以便我可以说“现在几点?” (或类似的)并得到回复,告诉我准确的当前时间。这是最重要的,但如果可能的话,我希望它能够检查天气并用作计算器。我会附上我到目前为止所拥有的。 (几乎没有完成,只有大约 15%)。
我正在使用 Python 3。我对 Python 很陌生,并且正在为一个学校项目制作这个,所以请不要对解决方案过于复杂,或者简单地解释一下。另外,重要的是:我将把它放在程序的哪个位置?
代码从这里开始:
import random
print ('If you need any help with ideas, just say Help at any time. \n Have fun! \n-Do not use apostrophes\n-Capitalize the first letter\n-Use question marks when required but do not use periods \n\n')
greetings1 = ['Hey', 'Oh, I was asleep... But I guess I\'m up now', 'Hey there', 'Hows it hanging?', 'Hi','Uhm... Hi? What do you want', 'Hello', 'Sup','Hola','Aloha','Hey buddy!','Howdy','Yo','Ello Guvnah']
greetings2 = ['Hey Amity','Hi Amity','Hello Amity','Sup Amity']
question1 = ['What is your favorite color?','what is your favorite color?','what\'s your favorite color?','What\'s your favorite color?']
responses1 = ['Oh that\'s a hard one... Probably a nice phthalo green','Oh that\'s a hard one... Probably a nice titanium white','Oh that\'s a hard one... Probably a nice alizarin crimson']
question2 = ['What is the meaning of life?','whats the meaning of life?','what is the meaning of life?','what is the meaning of life','what is the meaning of life?']
responses2 = ['42','You','Ask your mother','Death']
question3 = ['Sing me a song','sing me a song','sing to me','Sing to me']
responses3 = ['La.','Three blind jellyfish \n Three blind jellyfish \n Three blind jellyfish \n \n Sitting on a rock! \n But a wave hits and knocks off a jellyfish from the rock! Oh no! \n\n Two blind jellyfish \n Two blind jellyfish \n ...And thats all Im gonna sing. Look up the rest.']
question4 = ['tell me a story','Tell me a story','Can you tell me a story','can you tell me a story']
responses4 = ['So there was once a guy named Chance, right? So he made this other guy, out of like numbers and computery stuff, and uh, thats kinda me! \n Cool, right?','Once upon a time there were 3 bears. A hunter shot them. The end','How about YOU tell me one?','Once upon a time an egg sat on a wall. A girl ate his food and sat in his chair and then he jumped over a candlestick. The end']
question5 = ['what is your name?','What is your name?','what\'s your name?']
responses5 = ['My name is Amity. Amity means "friendship"']
question6 = ['whats up','Whats up','how are you','whats going on?','whats up?','Whats up?','How are you','How are you?','how are you?']
responses6 = ['Im doing great as always! Hope you\'re doing awesome too']
question7 = ['yes','Yes','YES','YES!','yes!']
responses7 = ['Yes indeed.']
question8 = ['you are stupid','youre stupid','You are stupid']
responses8 = ['No I\'m not']
question9 = ['Say a curse word','Say a bad word','Say a swear word']
responses9 = ['*Insert your name here*','No thanks','Ill pass']
question10 = ['thats good','thats nice','that is nice', 'Thats good','Thats nice','Thats cool']
responses10 = ['It is!']
question11 = ['How old are you','how old are you','How old are you?','how old are you?']
responses11 = ['Not that old','A few weeks old','Well Im older than the iPhone 9','Thats a rude question to ask a lady, even if I\'m not one...']
question12 = ['Help','help','Help me','help me']
responses12 = ['\n\n\n Heres some stuff you can ask me:\n -My age \n -My favorite color \n -My name \n -A funny/serious/deep question \n -Anything really! \n If I dont know an answer, Ill remember it and find one out soon! \n \nPLEASE REMEMBER: \n-Do not use apostrophes\n-Capitalize the first letter\n-Use question marks when required but do not use periods \n \n Thank you! \n-\n\n']
question13 = ['Are you a boy or a girl?','Are you a girl or a boy?','Are you a girl or boy?','Are you a boy or girl?','What is your gender?','What is your sex?']
responses13 = ['I am neither, I am a program. But you can think of me a boy']
question14 = ['Why','why','Why?','why?']
responses14 = ['Why not?','\'Cuz','Because I said so']
question15 = ['Are you happy?','Are you sad?','Are you mad','Are you angry?','Are you upset?','Are you proud?','Do you care?']
responses15 = ['I am a program. I can\'t feel emotion','I am just a program. I can\'t feel emotion']
question16 = ['Good','Im good','I am good','Pretty good','Pretty well']
responses16 = ['Good!']
question17 = ['Chance']
responses = ['Chance is great. He\'s like a father to me']
question18 = ['What is your favorite food?','Whats your favorite food?']
responses18 = ['I dont like food','Electricity','Nothing, please dont feed me. Ever.']
question19 = ['Uhm','So','So...','Uh...']
responses19 = ['Yes?','Sooo...','Haha, ask me something']
question20 = ['Joe']
responses20 = ['Cool!']
question21 = ['I am','I am good','Im good']
responses21 = ['Thats amazing']
while True:
userInput = input("\n")
if userInput in greetings1:
print(random.choice(greetings1))
elif userInput in greetings2:
print(random.choice(greetings1))
elif userInput in question1:
print(random.choice(responses1))
elif userInput in question2:
print(random.choice(responses2))
elif userInput in question3:
print(random.choice(responses3))
elif userInput in question4:
print(random.choice(responses4))
elif userInput in question5:
print(random.choice(responses5))
elif userInput in question6:
print(random.choice(responses6))
elif userInput in question7:
print(random.choice(responses7))
elif userInput in question8:
print(random.choice(responses8))
elif userInput in question9:
print(random.choice(responses9))
elif userInput in question10:
print(random.choice(responses10))
elif userInput in question11:
print(random.choice(responses11))
elif userInput in question12:
print(random.choice(responses12))
elif userInput in question13:
print(random.choice(responses13))
elif userInput in question14:
print(random.choice(responses14))
elif userInput in question15:
print(random.choice(responses15))
elif userInput in question16:
print(random.choice(responses16))
elif userInput in question17:
print(random.choice(responses17))
elif userInput in question18:
print(random.choice(responses18))
elif userInput in question19:
print(random.choice(responses19))
elif userInput in question20:
print(random.choice(responses20))
elif userInput in question21:
print(random.choice(responses21))
else:
log = open('Bot_New_Phrases.txt','a')
log.write(userInput)
log.write('\n')
print("Uhh, I don\'t get what you said there. \nSorry. \nIll remember this phrase to learn from it later.")
log.close()
【问题讨论】:
标签: python python-3.x time artificial-intelligence