Question: Use programming concepts only from the chapter Decision structure, Repetition structure, Function, Files and Exceptions, Lists / Tuples and Strings. Q# 4 : ( 7
Use programming concepts only from the chapter Decision structure, Repetition structure, Function, Files and Exceptions, ListsTuples and Strings. Q#: pointsWrite a Python program that:
Uses a given filename, sample.txt to read from.
Asks the user how many lines they want to read from this file.
Reads the specified number of lines from sample.txt or all available lines if the file has fewer than the requested number
Stores the lines in a list called lineslist
Performs the following operations on lineslist.
Create a list comprehension to store the length of each line in a list called linelengths.Create a list comprehension to store only the lines that contain more than characters in a list called longlines.Calculate the average length of readed lines on lineslist and store it in a variable called averagelength.
Prints the following:
The original lineslist.The linelengths list.The longlines list.The averagelength of readed lines.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
