0

Here is the basis of my assignment: write a script that reads through textfile.txt. The script will create a file named textfile-selected-words.txt. The new textfile-selected-words.txt file shall contain all of the words in textfile.txt that contain the letter 'j', either upper-case or lower-case. If the word in textfile.txt does not contain the letter 'j', it is "ignored". I am to use the readline method of the file object. It is also suggested to use the in operator.

This is what I have been able to come up with, however the new textfile-selected-words.txt file is being created but does not contain anything. I don't know where I missed a step.

f = open('textfile.txt')
h = open('textfile-selected-words.txt', 'w')
line = f.readline()
while line:
    if 'j' in line and 'J' in line:
        h.write()
        line = f.readline()
f.close()
h.close()   
user3315421
  • 1
  • 1
  • 1

0 Answers0