Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please help with the code using VS CODE / python. images of 6-1-lines1.txt and 6-1-lines2.txt uploaded In addition to the objectives covered in the previous

Please help with the code using VS CODE / python.

images of 6-1-lines1.txt and 6-1-lines2.txt uploaded

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

In addition to the objectives covered in the previous chapter, you must include the following techniques, as demonstrated in your current textbook, to receive full credit for the assignment objectives portion of the Code Grading Rubric: - File Input - File Output - Opening Files - Closing Files - Using Loops to Process Files - Processing Records - Exceptions 1. File Head Display (adapted from \#2) - Save the file as ch6_ex1.py Write a program that asks the user for the name of a file. The program should display only the first five lines of the file's contents. If the file contains less than five lines, it should show its entire contents. Test the program using the following text files (download from BlackBoard assignment page): 6-1-lines1.txt 6-1-lines2.txt Your program must: - Open file designated by user input for reading - Use a loop to read no more than five lines from the file - Strip the trailing from each line. (See: Reading a String and Stripping the Newline from It on page 315) Otherwise, your output will be double spaced. - Be able to handle files that have any number of lines (more or less than five lines - neither test file has exactly five lines) - Close the file The output should look like this for 6-1-lines1.txt: Enter the name of the file: 6-1-lines1.txt Line 01 Line 02 Line 03 Line 04 Line 05 The output should look like this for 6-1-lines2.txt: Enter the name of the file: 6-1-lines2.txt This file only has two lines Line 01 Line 02 Line 03 Line 04 Line 05 Line 06 Line 07 Line 08 This file only has two lines

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Modern Database Management

Authors: Jeffrey A. Hoffer Fred R. McFadden

9th Edition

B01JXPZ7AK, 9780805360479

More Books

Students also viewed these Databases questions

Question

Prepare a short profile of Lucy Clifford ?

Answered: 1 week ago

Question

Prepare a short profile of Rosa parks?

Answered: 1 week ago

Question

Prepare a short profile of victor marie hugo ?

Answered: 1 week ago

Question

Prepare a short profile of Henry words worth Longfellow?

Answered: 1 week ago