Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/314.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 虚拟助手代码跳过if语句_Python_If Statement - Fatal编程技术网

Python 虚拟助手代码跳过if语句

Python 虚拟助手代码跳过if语句,python,if-statement,Python,If Statement,我已经开始做我自己的虚拟助手了。这几天前效果很好,但我相信我把事情搞砸了。它应该找出我键入的命令,然后响应,但它总是说“问候语”——响应 from time import ctime import time import os import requests, json import random import pyttsx3 engine = pyttsx3.init() startup = ["Starting Ares...", "Booting up

我已经开始做我自己的虚拟助手了。这几天前效果很好,但我相信我把事情搞砸了。它应该找出我键入的命令,然后响应,但它总是说“问候语”——响应

from time import ctime
import time
import os
import requests, json
import random
import pyttsx3


engine = pyttsx3.init()


startup = ["Starting Ares...", "Booting up Ares..."]
selected_startup = random.choice(startup)


print(selected_startup)
engine.say(selected_startup)
engine.runAndWait()

command = input("Enter Command:")



def main():
    commands()

def commands():
    if command == "Hey" or "Hello" or "Hi" or "Ares":
        greetings = ["Hello, sir. What can I help you with?", "How can I be of assistance today, sir?", "Yes?"]
        selected_greeting = random.choice(greetings)
        print(selected_greeting)
        engine.say(selected_greeting)
        engine.runAndWait()


    elif command == "how are you":
        print("I am well, thank you. What can I do for you?")

    elif command == "What's the time?" or "What time is it?" or "What's the time, Ares?" or "What time is it, Ares" or "Time":
        dates = ["Todays date is ", "Today is "]
        selected_date = random.choice(dates)
        print(ctime())
        engine.say(selected_date + ctime)
        engine.runAndWait


    elif command == "Stop":
        print("Shutting down...")
    

    else:
        print("I'm sorry, I didn't quite catch that.")        

if __name__ == '__main__':
    commands()
例如,若我说“嘿”,它应该用一个问候语来回应,但不管我打什么,它总是用问候语来回应

我不知道它怎么了。这可能真的很简单。谢谢大家:)

哦!非常感谢。 问题是我用了

command == "something"
而不是使用

command in {"something"}
再次感谢您

代码
命令==“嘿”或“你好”或“你好”或“战神”
并不像您想象的那样。请改为在{“嘿”、“你好”、“你好”、“战神”}中使用
命令。另见