首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >虚拟助手-代码跳过if语句

虚拟助手-代码跳过if语句
EN

Stack Overflow用户
提问于 2021-04-16 15:17:40
回答 1查看 13关注 0票数 0

我已经开始开发我自己的虚拟助手了。这在几天前工作得很好,但我相信我搞砸了。它应该找出我输入的命令,然后响应,但它总是显示'greeting'-response。

代码语言:javascript
复制
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()

例如,如果我说“嘿”,它应该以一个问候语响应,但无论我输入什么,它总是以问候语响应。

我不知道它出了什么问题。这可能真的很简单。谢谢你们:)

EN

回答 1

Stack Overflow用户

发布于 2021-04-17 00:30:02

噢!谢谢。问题是我用了

代码语言:javascript
复制
command == "something"

不是使用

代码语言:javascript
复制
command in {"something"}

再次感谢你

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/67120751

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档