2016-08-17 25 views
1

我正在開發一個允許用戶輸入查詢的Python故障排除應用程序。此查詢將包含設備的品牌以及問題的症狀或問題。我正在編寫一個腳本,它基本上對查詢進行剖析,以便根據設備的關鍵字和品牌找到適當的解決方案。用於查詢選擇的內聯用戶數據輸入操作| Python

目前代碼: #IMPORT模塊 進口警告

#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() 

目前,該腳本將確定一個品牌,但我不如何才能跟隨檢查寬一些關鍵字一定解決途徑。我希望解決方案能夠按照選擇一個品牌的特定品牌的次要陣列的模式,其中包含一些潛在的錯誤。每個錯誤都可以定義一個解決方案。

我將不勝感激任何見解,

感謝,

山姆

+0

嘿,我其實不太擅長Python。我怎樣才能在我的口譯員中運行?我目前得到這個錯誤信息:「SyntaxError:編譯單個語句時發現多個語句」。 – gordlonious

+0

嗨Gordlonious,我一直在Python Shell v3.5.2中運行它。我希望這是最明顯的錯誤。謝謝你的幫助,這是非常感謝,山姆:-) –

回答

0

運行此我希望這給你一些想法。您需要修復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.." 
+0

Python有一個很酷的ftplib'ftplib'模塊,我希望能與'我們'的新服務器一起工作。 '從ftplib導入FTP'。該文檔使其看起來非常簡單。在我第一次嘗試時,我無法連接到我的FTP站點。但是,Windows 10的內置外部ftp已成功。 'ftp ftp.url'。然後驗證。 #today – gordlonious

+0

謝謝 - 我會試一試並回復你! :-) –

+0

嗨gordlonious,我已經達到了這一點 - https://github.com/KentCoding/phoneTroubleshooting/blob/master/phoneTroubleshooting.py。我現在正在嘗試設置關鍵字過濾系統。但現在設置了錯誤檢測。你到目前爲止的想法是什麼?山姆 –

相關問題