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
- 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.
- Construct conditional selection statements that use the restricted uses of execution control structures.
- Open and close les.
- Read and analyze data read in from a file.
- 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:
- The file must start with an integer, n
- 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.dat
10
1
2
3
4
5
6
7
8
9
bad2.dat
ten
1
2
3
4
5
6
7
8
9
bad3.dat
10
one
2
3
4
5
6
7
8
9
bad4.dat
10
1
2
3
4
5
6
7
8
9
10
11
good.dat
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
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started