0

As part of my assignment I'm trying to write a program that reads a text file and unifies all the words in that text file together. I made the code so far but it is not working for me and I do not know how else to proceed. What am I missing?

def problem2(filename):
    func = open(filename, 'r')
    string = ''
    for line in func:
        string += line
    func.close()
    return string
print(problem2("lol.txt"))
Random Davis
  • 6,662
  • 4
  • 14
  • 24
  • 1
    If you replace `for line in func:` with `for line in func.readlines():` does that solve the issue? – Random Davis Dec 21 '20 at 17:17
  • hello, no it didn't. still showing the words separetly – user14866862 Dec 21 '20 at 19:25
  • Okay did you try this? https://stackoverflow.com/questions/15233340/getting-rid-of-n-when-using-readlines – Random Davis Dec 21 '20 at 19:31
  • 1
    This might be a good time for you to practice your debug skills. The following three references give excellent advice on debugging your code. [How to debug small programs](https://ericlippert.com/2014/03/05/how-to-debug-small-programs/), [Six Debugging Techniques for Python Programmers](https://medium.com/techtofreedom/six-debugging-techniques-for-python-programmers-cb25a4baaf4b) or [Ultimate Guide to Python Debugging](https://towardsdatascience.com/ultimate-guide-to-python-debugging-854dea731e1b) – itprorh66 Dec 22 '20 at 00:17
  • 2
    Welcome to Stack Overflow. [This answer](https://stackoverflow.com/a/44953154) in the already linked question does exactly what you want. – bad_coder Dec 22 '20 at 00:26
  • Can you post a sample of the output you are getting along with a sample of the output you expect? – Scott Swezey Dec 22 '20 at 00:26

0 Answers0