2016-10-10 65 views
-6

以下代碼被設計爲Python中的自動化故障排除程序。Python「故障排除機器」需要修復

# Welcoming the user to the program 
print("Hello this is a automated mobile phone troubleshooter ") 
print("The code will ask you a few questions try to answer them to the best of your ability") # Explaining what the code will do 

# A list storing all the questions the code will ask the user 
questions = ["Is there a problem with your hardware or is do you need technical assistance. Please type technical assistance or hardware", 
      "Have you dropped your phone recently? Please type Yes or No", 
      "Is your phone able to charge? please type Yes or No", 
      "Is your phone a iphone? Please type yes or no", 
      "Does your phone keep freezing? Please type yes or no", 
      "Can your phone connect to wifi? please type either yes or no", 
      "Have you gotten your phone wet? ", 
      "Is the phone's screen cracked or broken? ", 
      "Is there a problem with the camera? ", 
      "Is the problem with phone fixed? "] 
# A list containing all the solutions that will be given to the user 
solutions = ["This troubleshooter is only for hardware problems please call 01474 709853 for technical assistance", 
      "Please try turning it off and on again", 
      "Try changing the cable you charge the phone with", 
      "Please hold the lock button and home button for 5 seconds this causes a force restart", 
      "Try deleting some data to make your phone run faster E.G. Delete applications", 
      "Try restarting your router", 
      "Put your phone in a bowl of rice overnight", 
      "Take the phone to the manufacturer's store", 
      "Uninstall any third party apps or applications that you have downloaded since the camera has not been working", 
      "Please take the phone to your local phone manufacturers store and ask them for help"] 
answers = ["technical assistance","yes","no","yes","yes","no","yes","yes","yes","no"] 
validation = ["hardware","no","yes","no","no","yes","no","no","no","yes"] 
answer = "a" 
# Creating a loop and making the variable loop go from 0 to 9 
for loop in range(0,10): 
    while answer != answers[loop] and answer != validation[loop]: 
     answer = input(questions[loop]) 
     # Turning the user's answer and turning it to lowercase making sure the IF statement gets the right answer 
     answer = answer.lower()  
     if answer == answers[loop]: 
      # prints the solution the problem 
      print(solutions[loop]) 
      else goto 

print("Thank you for using the automated troubleshooting program goodbye") 

我不能得到這個代碼正常運行,因爲它結束之前,是否有任何人能方式幫助它可以採取的兩個問題一個最大輸入?

+0

你可以嘗試代碼框格式的代碼? http://meta.stackexchange.com/questions/22186/how-do-i-format-my-code-blocks –

+0

請正確格式化您的代碼。如果系統不允許你用一個巨大的代碼塊和小文本進行詢問,那麼有一個原因(cc。@MartinGottweis)。你的問題缺乏信息。請閱讀[問]。 –

+2

上次我看到* goto *就像25年前一樣玩c64基本:) – grubjesic

回答

-1

用「if語句」和raw_input做什麼?

x = raw_input("Is there a problem with your hardware or is do you need technical assistance. Please type technical assistance or hardware") 

if x == ("technical assistant"): 
    print("This troubleshooter is only for hardware problems please call 01474 709853 for technical assistance") 

if x == ("hardware"): 
    x1=raw_input("Have you dropped your phone recently? Please type Yes or No") 

if x1 == ("No"): 
    x2=raw_input("Is your phone able to charge? Please type Yes or No") 

等等...

+0

你的答案不清楚,並且它可以很容易地導致一個未定義的'x1'。 –