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

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899604
Joined: Mon Aug 02, 2021 8:13 am

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

Post 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 .
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply