i am coding the AI with python but i have a problem I want it to print out the answer if the question has keywords of KeyS the error when running is in the line:
if you == KeyS:
robot = 'hi friend'
i have tried this code:
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()
my english is not good.so please forgive me if there is any grammar mistake
You need to change
if you == KeyS:
robot = 'hi friend'
to
if you in KeyS:
robot = 'hi friend'
Since KeyS is a tuple of strings.