python - 虚拟助手代码跳过 if 语句
问题描述
我已经开始研究我自己的虚拟助手了。几天前这很好用,但我相信我搞砸了。它应该找出我输入的命令然后响应,但它总是说“问候”-响应。
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"}
再次感谢你
推荐阅读
- flutter - When user changes the text size in their display settings, my flutter app text size is also changing and it is disturbing nearby widgets
- sql - 排除其中两列的值都为零的行,而不是一个或另一个
- spring-boot - Backbase Integration with Spring Microservices
- python - 如何在嵌入 discord.py 中将长字段作为页面发送?
- java - 如何在 mapstruct 接口中注入 guice 依赖项 - java
- python-3.x - 如何从每日收益中计算价格?
- input - 列表理解 - 多个输入
- reactjs - React Hooks 和 React Query (useQuery):仅在单击按钮时调用 API 调用/查询
- c# - .NET Core 3 Web API:[FromBody] 如何绑定抽象类属性
- powershell - 从 cmd 和 PowerShell 将分号作为参数传递给 .bat 文件