Page 1 of 1

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 e

Posted: Sun May 15, 2022 8:49 am
by answerhappygod
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.
That short line is not printed. Your program must use readline() to
read one line at a time. Remember that a newLine is a character
too. For your testing you should create a file named infile.txt.
Only upload your Python program, I will create my own infile.txt.
Your loop should be controlled by a loop that uses a condition
involving either < or <= . Please use a while-loop BUT do not
use break . Also only have ONE condition in your solution; do NOT
have if anotheCondition: inside your loop Hint: Determine the
length of the first line of the file before the loop. The length of
the second and subsequent should be examined inside the body of the
loop. You could also look at the first few programs that Zelle
covers dealing with while .