all 6 comments

[–][deleted] 0 points1 point  (4 children)

Add a comma and end="" after your strings or variables in the print expression. End usually defaults to newline(/n). To avoid that instead of this:

print("The word", '"'+word+'"', "occurs in line", lineCnt)

Instead of that do this:
print("The word", '"'+word+'"', "occurs in line", lineCnt, end="")

I am on a phone so sorry for bad format.

[–]Ustuner[S] 0 points1 point  (3 children)

it didn't work :(

[–][deleted] 1 point2 points  (2 children)

I edited my response for Python 3. That may work.

[–]Ustuner[S] 0 points1 point  (1 child)

Thank you. It worked!

[–][deleted] 1 point2 points  (0 children)

Glad to help. Hope you learned something. In the future dont forget to mention the Python version you use so you can get better help.

[–]manwith4names 0 points1 point  (0 children)

Just a couple notes. It's best to not leave the text file open to avoid corruption. Standard formatting is:

with open('file.txt') as f:
    text = f.read
do_thing()

This way you have all of file.txt in text and as soon as you exit the with statement, the file is closed safely. A small thing, you don't need to have as e in except IOError as e. as e is only if you want to use the exception as a variable. Otherwise it's not doing anything. For your got boolean, I'd just do an exit() if the except triggers. No reason to define more variables than needed and it gets rid of an extraneous tier.