我正在用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 = "http://stackoverflow.com/questions/372885/how-do-i-connect-to-a-mysql-database-in-python"
url1 = "https://docs.python.org/3/reference/datamodel.html#object.__contains__"
url2 = "مرحبا I think python is very unicode friendly.."