如果x属于关键词AI会自动回答

if x belongs to keywords the AI will automatically answer

我正在用 python 编写 AI,但我遇到了问题 如果问题有 KeyS 关键字,我希望它打印出答案 运行 在行中时的错误:

if you == KeyS:
    robot = 'hi friend'

我试过这个代码:

import time
import pyttsx3

day = time.asctime(time.localtime(time.time()))
KeyS = 'hi', 'hello'

loop = True
while loop:
    you = input('you:')
    if you == KeyS:
        robot = 'hi friend'
    elif you == 'time':
        robot = day
    elif you == 'bye':
        robot = 'bye sir'
        print('robot:' + robot)
        robotsay = pyttsx3.init()
        robotsay.say(robot)
        robotsay.runAndWait()
        exit()
    else:
        robot = 'i do not understand'
    print('robot:' + robot)
    robotsay = pyttsx3.init()
    robotsay.say(robot)
    robotsay.runAndWait()

我的英文不会good.so如有语法错误请见谅

你需要改变

  if you == KeyS:
        robot = 'hi friend'

  if you in KeyS:
        robot = 'hi friend'

因为 KeyS 是一个字符串元组。