Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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.datimage text in transcribed

10

1

2

3

4

5

6

7

8

9

bad2.datimage text in transcribed

ten

1

2

3

4

5

6

7

8

9

bad3.datimage text in transcribed

10

one

2

3

4

5

6

7

8

9

bad4.datimage text in transcribed

10

1

2

3

4

5

6

7

8

9

10

11

good.datimage text in transcribed

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

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_2

Step: 3

blur-text-image_3

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

Mastering Apache Cassandra 3 X An Expert Guide To Improving Database Scalability And Availability Without Compromising Performance

Authors: Aaron Ploetz ,Tejaswi Malepati ,Nishant Neeraj

3rd Edition

1789131499, 978-1789131499

More Books

Students also viewed these Databases questions

Question

(b) What are the generators? Pg45

Answered: 1 week ago