0

I'm writing a program where the user inputs something and then the code looks in a text file and reads line by line, if what they entered is in a specific line than the code prints something depending on the line it's in. Here is what I have come up with, however when ran my code seems to produce nothing.

sol1 = "generic solution 1"
sol2 = "generic solution 2"

q = input("bla bla bla\n")

def test():

   with open("textfile.txt") as t:
       line1 = t.readlines(1)

       line2 = t.readlines(2)

       for q in t:
           if q in line1:
               print(sol1)

           elif q in line2:
               print(sol2)           
test()

Could someone tell me what I've done wrong or any areas where I can improve the code. The textfile contains this

screen touchscreen

battery charge

  • There are many issues with your code. A lot of statements do something different than what you think they do. I could spoil it for you, but to actually learn something read and apply this: https://ericlippert.com/2014/03/05/how-to-debug-small-programs/ – timgeb Mar 07 '17 at 21:18
  • I agree with timgeb, you should really take the time to debug this yourself. Read about all the methods you are using, and make sure you understand them. – juanpa.arrivillaga Mar 07 '17 at 21:20

0 Answers0