Chapter 6 - Files and Files and Exceptions Complete the following programming exercises adapted from those...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
Chapter 6 - Files and Files and Exceptions Complete the following programming exercises adapted from those found at the end of Chapter 6: But note - I have made significant modifications and added steps to these problems that must be completed to receive full credit. Assignment Objectives 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: Your program MUST USE the main function, which must be called correctly (use the template). Additionally, you must include docstrings as shown in the template. 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. The file should show its entire contents if it contains less than five lines. Test the program using the following text files: 6-1-lines1.txt E 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 6-1-lines1.txt Download 6-1-lines1.txt (70 Bytes) Line 01 Line 02 Line 03 Line 04 Line 05 Line 06 Line 07 Line 08 6-1-lines2.txt Download 6-1-lines2.txt (29 Bytes) This file only has two lines Chapter 6 - Files and Files and Exceptions Complete the following programming exercises adapted from those found at the end of Chapter 6: But note - I have made significant modifications and added steps to these problems that must be completed to receive full credit. Assignment Objectives 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: Your program MUST USE the main function, which must be called correctly (use the template). Additionally, you must include docstrings as shown in the template. 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. The file should show its entire contents if it contains less than five lines. Test the program using the following text files: 6-1-lines1.txt E 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 6-1-lines1.txt Download 6-1-lines1.txt (70 Bytes) Line 01 Line 02 Line 03 Line 04 Line 05 Line 06 Line 07 Line 08 6-1-lines2.txt Download 6-1-lines2.txt (29 Bytes) This file only has two lines
Expert Answer:
Related Book For
Income Tax Fundamentals 2013
ISBN: 9781285586618
31st Edition
Authors: Gerald E. Whittenburg, Martha Altus Buller, Steven L Gill
Posted Date:
Students also viewed these programming questions
-
Let A, B be sets. Define: (a) the Cartesian product (A B) (b) the set of relations R between A and B (c) the identity relation A on the set A [3 marks] Suppose S, T are relations between A and B, and...
-
Managing Scope Changes Case Study Scope changes on a project can occur regardless of how well the project is planned or executed. Scope changes can be the result of something that was omitted during...
-
The data in the chart below is for the distance (in cm) to the near point, the point nearest the eye at which the eye can accurately focus, at a persons age. Age (years) Near Point (cm) 10 7.5 20 9...
-
Develop a few guidelines for spreadsheet developers to follow to help prevent spreadsheet errors?
-
The Whole Company is an integrated multidivisional manufacturing firm. Two of its divisions, Rod and Champ, are profit centres and their division managers have full responsibility for production and...
-
Brian Rafferty ingested finasteride, a drug prescribed to him to treat an enlarged prostate. Finasteride is a generic version of Proscar, a drug manufactured by Merck. Some time after he started to...
-
(Entries for Life Cycle of Bonds) On April 1, 2010, Seminole Company sold 15,000 of its 11%, 15-year, $1,000 face value bonds at 97. Interest payment dates are April 1 and October 1, and the company...
-
Consider the closed system with mass-action rate constants as shown. Suppose the rate constants are (in min-1) k = 0.05, kg = 0.7, k2= 0.005, and k4 = 0.4. ki k3 A B C k2 ka (a) Construct a...
-
Richmond Office Supplies buys and sells office stationery and supplies. It follows a cost leadership strategy, seeking to provide customers with market-beating prices. Recently as a new graduate...
-
Brock Newman has prepared his annual financial statements in order to analyze the data. The data provided are items from Brock's balance sheet and income and expense statement. Use the data provided...
-
An objects polar moment of inertia, J, represents itsresistance to twisting. For a cylinder, this moment of inertia isgiven by this formula: J = mr2 / 2 + m(l2 + 3r2) / 12 m is thecylinders mass...
-
The Oompa Loompas is using an electric winch to help construct anew part of the factory on Mars. The winch is 81% efficient. Thewinch lifts an object with a weight of 1,800 pounds force [lbf] toa...
-
An investor is evaluating an mutual fund investment she made five years ago. Over the past five years, the mutual fund's annual returns have been as follows: Annual Return Year 2011 0.92% 2012 9.69%...
-
A company normally takes 24 days to pay for average daily credit purchases of $11,250. Its average daily sales are $15.750, and it collects accounts in 29 days. What is its net credit position?
-
Required information [The following information applies to the questions displayed below.] The April 30 bank statement for KMaxx Company and the April ledger account for cash are summarized here:...
-
A local politician is concerned that a program for the homeless in her city is discriminating against blacks and other minorities. The following data were taken from a random sample of black and...
-
The following additional information is available for the Dr. Ivan and Irene Incisor family from Chapters 1-6. On December 12, Irene purchased the building where her store is located. She paid...
-
Van makes an investment in a partnership in 2012. Van's capital contributions to the partnership consisted of $30,000 cash and a building with an adjusted basis of$70,000, subject to a nonrecourse...
-
Diego, age 28, married Dolores, age 27, in 2012. Their salaries for the year amounted to $46,479 and they had interest income of $3,500. Diego and Dolores' deductions for adjusted gross income...
-
In January 2014, installation costs of 6,000 on new equipment were charged to Maintenance and Repairs Expense. Other costs of this equipment of 30,000 were correctly recorded and have been...
-
Whittier Construction Co. had followed the practice of expensing all materials assigned to a construction job without recognizing any residual inventory. On December 31, 2015, it was determined that...
-
Prior to 2015, Heberling Inc. excluded manufacturing overhead costs from work in process and finished goods inventory. These costs have been expensed as incurred. In 2015, the company decided to...
Measures Of Risk Time Consistency And Surrogate Processes 1st Edition - ISBN: 3639100379 - Free Book
Study smarter with the SolutionInn App