mercredi 23 mars 2016

Python code is skipping to else

Hi so this is my code an for some reason after the last for loop the code just skips straight to the else statement and prints it about 4 times and then goes to the if statement and prints the solution. Please can someone help with this.

while True:
   d = {}
   with open("keyword_database.txt") as f:
       for line in f:
          (key,val) = line.split(":")
          d[str(key)] = val
   try:
      userinput=input(str("What is the problem with your phone?\nEnter here in lower:"))
      print()
   except:
      print ("Invalid Input")
   for word in userinput.split(): 
           if word in d:
              print(d[word])
              print()
           else:
              print("Please Re-Phrase your problem and Try Again")
              print()

And this is what it prints once I run the code.

What is the problem with your phone? Enter here in lower: my phone is broken

Please Re-Phrase your problem and Try Again

Please Re-Phrase your problem and Try Again

Please Re-Phrase your problem and Try Again

Problem = Broken Solution = Take your phone to the repair shop and get it fixed from there however do keep in mind if someone else opens your phone apart from apple then the warrenty will be VOID (NOT ACTIVE).

Aucun commentaire:

Enregistrer un commentaire