233k views
4 votes
Write a program that reads in a text file, infile.txt, and prints out all the lines in the file to the screen until it encounters a line with fewer than 4 characters. Once it finds a short line (one with fewer than 4 characters), the program stops. Your program must use readline() to read one line at a time. For your testing you should create a file named infile.txt. Only upload your Python program, I will create my own infile.txt using break

User YoniLavi
by
7.8k points

1 Answer

7 votes

Answer:

Step-by-step explanation:

f=open("infile.txt","r")

flag=True

while(flag):

s=f.readline().strip()

if(len(s)>=4):

print(s)

else:

flag=False

User Rinzy Kutex
by
7.1k points