用于查询选择的内联用户数据输入操作 | Python

Inline User Data Input Manipulation for Query Selection | Python

我正在 Python 开发故障排除应用程序,允许用户输入查询。此查询将包含设备的品牌以及问题的问题或症状。我正在编写一个脚本,该脚本本质上是剖析查询以根据设备的关键字和品牌找到合适的解决方案。

当前代码: #导入模块 导入警告

#Define Globals
brands = ["apple", "android", "windows"]
brand = ''

def Main():
    init()
    print("--Welcome to Troubleshooting Applet--")
    print("In your query please include the brand of your device and the problem / symptom of your current issue. \n")
    query = input("Enter your query: ").lower()
    brand = set(brands).intersection(query.split())
    if brand != '':
        print(brand)
    else:
        print("Brand in existance not defined")

def init():
    #warnings.filterwarnings("ignore") #Disable while debugging

if __name__ == '__main__':
    Main()

目前,该脚本将识别一个品牌,但我不确定如何检查大量关键字以遵循解决方案路线。我希望该解决方案遵循选择一个品牌的模式,该品牌是特定于该品牌的二级阵列,其中包含许多潜在错误。这些错误中的每一个都可以定义一个解决方案。

如有任何见解,我将不胜感激,

谢谢,

山姆

运行 这个 我希望这能给你一些想法。您需要修复 main(): 函数的缩进。

#Define Globals
brands = ["apple", "android", "windows"]
brand = ''
import random
def Main():
        init()
        print("--Welcome to Troubleshooting Applet--")
        print("In your query please include the brand of your device and the problem / symptom of your current issue. \n")
        query = input("Enter your query: ").lower()
        brand = set(brands).intersection(query.split())
        keywords = ['custom security keywords collection', 'item2', 'key3']
        index = 0
        for i in range(len(query)):
            if query.__contains__(keywords[index]): # __iter__() # could use 'in' keyword here
                #switch/decide
                text = 'run decision'
                print(keywords[index])
            else:
                if len(keywords) < 3:
                    index = index + 1
                text1 = 'continue'
        # OR
        # Test keyword idea...
        tKeyword = random.choice(keywords)
        # You need a lot of work to come up with error decisions right?
        # You may need to start pulling from a Database and checking against large documents?
        # just trying to come up with something to get you going
        print ('RANDOM keyword for TESTING:' + tKeyword)
        if brand != '':
            print(brand)
        else:
            print("Brand in existance not defined")

def init():
        ftp = 0
    #warnings.filterwarnings("ignore") #Disable while debugging

if __name__ == '__main__':
    Main()
    print('ask yourself about escape sequences and encoding for the query? \+'
          ' I believe utf-8 is the default encoding for python 3')

def dbconnect():
    url = ""
    url1 = "https://docs.python.org/3/reference/datamodel.html#object.__contains__"
    url2 = "مرحبا I think python is very unicode friendly.."