-2

I'm a beginner at python. I want the user to input a problem and then the program should pick out words and read the file accordingly. For example, if they used the word 'water' then it will read the appropriate line and print it. At the moment it only works if that key word is at the end out the inputted string.

screen = ["display", "screen", "broken", "glass", "cracked"]                 
software = ["frozen", "stuck", "weird", "flashing" , "virus" , "reboot" ,"loop"]
body = ["broken" , "dented" , "dropped" , "smashed"]
water = ["wet" , "water" , "rain" , "damage" , "damaged" , "toilet" , "damp"]  
heat = ["overheating" , "hot" , "burning" , "burn" , "warm"]

problem = input("Please tell me what is wrong with your phone! ")  #this is to break up the users input so the words can be found seperately in the list
for j in problem.split():
pass

if j in screen:
solution = open("sfs.txt","r")
solutionread = solution.readline()
solution.close()
print(solutionread)

The rest of the code uses the if elif else code. It also uses readline to read the line I need. I am not very experienced and still learning so please try give me simple answers as too making it work effectively. Thanks!

Morgan Thrapp
  • 9,748
  • 3
  • 46
  • 67
Samurai
  • 3
  • 3
  • 2
    Please format your code properly – Busturdust Feb 25 '16 at 20:38
  • Python requires proper indentation, are you sure you have that in your code? Also, what do you mean *Won't Always Print*? Be more specific. – Leb Feb 25 '16 at 20:39
  • Why do people keep asking about cell phone repair scripts? [1](http://stackoverflow.com/questions/35525074/how-do-i-split-the-solutions-in-my-code) [2](http://stackoverflow.com/questions/35584784/how-to-make-a-list-go-to-a-def) [3](http://stackoverflow.com/questions/35605188/if-statement-with-or-not-working-as-expected) – Kevin Feb 25 '16 at 20:41
  • Do you need to search through lists names or through items in lists? – Cosinux Feb 25 '16 at 20:43
  • @Kevin probably a recent hw assignment – Leb Feb 25 '16 at 20:43
  • Since you want it to **print** the line **if** it has a certain word in it, don't you think you should iterate (hint: keyword) over the lines of the **file** and then **if** it has that word **print** it? Right now you're just reading one line and printing it unconditionally. – Two-Bit Alchemist Feb 25 '16 at 20:53

1 Answers1

0

You code is not formatted with indents, so this may be wrong.

I suspect your indentation results in if j in screen: running after the for j... loop, not in it. Also, read the definition of pass.

Mike Ulm
  • 380
  • 1
  • 4
  • 14