Question: This assignment stems from an intermediate python course Lab Assignment Objectives Construct, starting from informal specications, loops that use the iteration, counter, accumulator, and/or nested

This assignment stems from an intermediate python course

Lab Assignment Objectives

  1. Construct, starting from informal specications, loops that use the iteration, counter, accumulator, and/or nested loop pattern as well as short functions that make use of such loop patterns.
  2. Construct conditional selection statements that use the restricted uses of execution control structures.
  3. Open and close les.
  4. Read and analyze data read in from a file.
  5. Identify and manage a run-time exception corresponding to the common exception types.

Understand the Application

It makes sense that the quality of a data analysis summary is contingent on the quality of the original data set.

This weeks program will perform a data verification of data files throwing an exception if the data input file violates certain conditions. If the data file is valid the program will process the data set.

The Program Specification

Write a program that enforces the following expectations of a data set file:

  • The file must exist
  • The data in the file must have the following format:
  1. The file must start with an integer, n
  2. The file must contain n data values

The program prompts the user for the name of a file. The file is expected to contain data values. The first line of the file should contain the total number of values, and the remaining lines contain the data.

Three key potential errors to program for include:

  • The file might not begin with an integer
  • There might not be a sufficient number of data values
  • There may be additional input after reading all data values

For a valid data file, the processing data task is to compute the sum of all the data values in the file. Print out a result message and the accumulated sum for a valid data file.

Testing Requirements

Error Checking: First, validate if the user supplied filename exists. Then run the following 5 test files provided to use as test cases for your program. 4 test cases are expected to raise exception conditions. 1 test case is a valid data set. Generate an accumulated sum for the valid data set.

***data provided on files entered below***

bad1.datThis assignment stems from an intermediate python course Lab Assignment Objectives Construct,

10

1

2

3

4

5

6

7

8

9

bad2.datstarting from informal specications, loops that use the iteration, counter, accumulator, and/or

ten

1

2

3

4

5

6

7

8

9

bad3.datnested loop pattern as well as short functions that make use of

10

one

2

3

4

5

6

7

8

9

bad4.datsuch loop patterns. Construct conditional selection statements that use the restricted uses

10

1

2

3

4

5

6

7

8

9

10

11

good.datof execution control structures. Open and close les. Read and analyze data

10

1

2

3

4

5

6

7

8

9

10

Here are some other tips and requirements:

1. Keep provided test files intact

2. Use a while loop to run test files as your input test suite to generate submission run output

3. Create user defined functions

4. Provide an appropriate display message both for invalid and valid data files.

5. Be sure to print out the sum value for a valid file.

Here is a sample partial run:

Please enter the file name: nofile.dat Error: file not found. Please enter the file name: bad1.dat Error: file contents invalid.  Please enter the file name: good.dat The sum is: 

Transcribed image text

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!