2017-01-19 3 views
0

INCOMPLETE CODEは

プログラミングAトラブルシューティングプログラムにはPython

だから私の割り当ての一つは、クエリ内のキーワードをindetify、その入力に基づくソリューションにユーザーをリンクしますtroublshootingプログラムを作成することです。このコードは動作しますが、キーワードのいずれかが常に最初の解決策を呼び出すでしょう...これを修正する方法に関するアイデア?どうもありがとう!あなたは

if ("battery" in problemexplainedone or 
    "swollen" in problemexplainedone"): 

if ("battery" or "swollen" in problemexplainedone): 
    print(sol1) 

などの出現箇所を変更する必要が

#CODE BEGINS 

#damaged screen# 
sol1 = ("If the battery of your mobile phone battery has swollen or changed appearance, we recommend removing the battery from the phone immediately and bringing them in store. This is something our technicians will have to look at.") 
sol2 = ("We recommend bringing the phone in to a nearby store in able to gain help from a specialist.") 
sol3 = ("We recommend factory resetting the phone or updating the mobile to the latest interface as the majority or errors are caused due to out-of-date interfaces.") 
#subjected to damage# 
sol4 = ("If the screen has been cracked, we recommend replacing the screen. If not, bring the phone into a store in order to seek help from a technician.") 
sol5 = ("If the phone is water logged, we recommend removing the battery and allowing each piece of the phone to dry separately. Alternatively take the phone into a store.") 
sol6 = ("We recommend taking the phone into a store, in order to seek help from a specialist.") 
#editing# 
sol7 = ("If you have recently changed the security settings on your phone there may be a corruption within your files. Please ensure you are entering your password correctly, and if this does not work, we recommend taking the phone into a store, in order to seek help from a specialist.") 
sol8 = ("If you have recently deleted or edited files there may be a corruption within the files. In which case, please drop in to a nearby specialist in order to seek professional help.") 
sol9 = ("If there has been a new update release for your device and many people are suffering a similar issue, there may be a manufacturing problem. We recommend taking the phone into a store, in order to seek help from a specialist.") 
#file corruption# 
sol10 = ("If you have recently attempted a factory reset and there has been an error you may need to retry this process. If the results come back the same, we recommend bringing the phone in to a nearby store in able to gain help from a specialist.") 
sol11 = ("If there is a corruption within your files you may need to take your phone into a nearby store to gain professional help. This will ensure none of your files get lost in the process of storing them.") 
sol12 =("We recommend factory resetting the phone or updating the mobile to the latest interface as the majority or errors are caused due to out-of-date interfaces.") 
#corruptions due to download# 
sol13 =("If you have recently download files from an external site there may be corruptions within the files or viruses. Please take your phone into a nearby store to gain professional help. This will ensure that no more damage is done to your device.") 
sol14 =("If you have recently downloaded something from the app store your storage may be too full for your phone to run. In which case, please clear some space on your device.") 
#If not solution can be provided, this outcome is the last message# 
sol15 = ("Unfortunately we were not able to identify your problem. If you feel as though you may have made a mistake, you can restart this test. If there is no available solution we would recommend taking the phone into a store, in order to seek help from a specialist.") 

import time 

boolean = 0 #I have decided to use boolean operators in a way that they will act as subfunctions. This will help in directing the user to a specific solution instead of a general one.# 


problemsolved = False 
while problemsolved == False: 
     print("Hello, this system consists of multiple queries that will aim to help solve any problems that have arisen with your mobile device. If no solution is available the case number will be stored and revisited as soon as possible by a member of our customer support team.") 
     print("Let's get started, shall we?") 
     while boolean == 0: 
      problem1 = input("Is there something visably wrong with the phone?") 
      if problem1 == "yes": 
       print("Please describe in more detail.") 
       boolean += 1 
      elif problem1 == "no": 
       print("The problem is not to do with visable damage") 
       boolean+= 2 
     while boolean == 1: 
      problemexplainedone = str(input("Please decribe what is wrong with your phone.")) 
      if ("battery" or "swollen" in problemexplainedone): 
       print(sol1) 
      elif ("screen" or "display" in problemexplainedone): 
       print(sol2) 
      elif ("error" or "message" in problemexplainedone): 
       print(sol3) 
     programfinished = input("Has the source of the problem been found and a solution suggested?") 
     if programfinished == "yes": 
      system = False 
      time.sleep(3) 
      exit() 
     elif programfinished == "no": 
      boolean += 1 

     while boolean == 2: 
       problem2 = input("Has the phone been subjected to damage?") 
     if problem2 == "yes": 
       print("Please describe in more detail.") 
       boolean += 1 
     elif problem1 == "no": 
       print("The problem is not to do with trauma to the hardware") 
       boolean+= 2 


     while boolean == 3: 
      problemexplainedtwo = str(input("Please decribe what is wrong with your phone.")) 
      if ("battery" or "swollen" in problemexplainedtwo): 
       print(sol4) 
      elif ("screen" or "display" in problemexplainedtwo): 
       print(sol5) 
      elif ("error" or "message" in problemexplainedtwo): 
       print(sol6) 
     programfinished = input("Has the source of the problem been found and a solution suggested?") 
     if programfinished == "yes": 
      system = False 
      time.sleep(3) 
      exit() 
     elif programfinished == "no": 
      boolean += 1 
+0

ヒント:2つ以上の可能な値を保持する場合は、「ブール値」ではありません。 – deceze

+0

このコードが現在行っていることと、それがどうなっているのかがどのように異なるのかを、より明確に説明してください。 – deceze

+0

括弧は文字列変数の代入( 'foo =(" bar ")ではなく' foo = "bar")や 'if'ステートメントの条件のどちらでもないことに注意してください。 – poke

答えて

1

それ以外の場合は、常に最初のソリューションを選択、Trueを返します。

他のif(... in ...)構成と同じです。

また、いくつかの非関連のヒント:

  • 直接インデックスでソリューションを選択することが容易になりますソリューションの配列を、使用してください。
  • ブール型変数を使用せず、数値に割り当てます。変数にはより良い名前を付けてください。
  • 問題が解決されないうちに問題が解決されました。解決済み==偽:
  • problemSolved
関連する問題