简单AI程序:问候语和基本回复
以下是一个比较简单的AI程序,它可以回答用户的问题并提供一些帮助。当用户输入问候语时,程序会回复一个随机的问候语;否则,程序会回复一个随机的回复。这个程序只是一个很简单的示例,但它展示了如何创建一个基本的AI程序。
# 导入必要的库
import random
# 创建一个问候语列表
greetings = ['Hello', 'Hi', 'Hey there', 'Greetings', 'What's up', 'Yo']
# 创建一个回复列表
responses = ['How can I assist you?', 'What can I do for you?', 'Is there anything you need help with?']
# 创建一个函数来处理用户问题
def process_question(question):
# 如果用户说'你好',就回复问候语
if question.lower() == 'hello' or question.lower() == 'hi':
return random.choice(greetings)
# 否则,就回复随机的回复
else:
return random.choice(responses)
# 主程序
while True:
# 获取用户输入
user_input = input('What can I help you with today? ')
# 处理用户输入
response = process_question(user_input)
# 输出回复
print(response)
原文地址: https://www.cveoy.top/t/topic/mV2S 著作权归作者所有。请勿转载和采集!