Create the following program: Read a data file (data.csv download from Canvas) in a try, except, else, finally structure and calculate the total of all numbers contained in the file. ▸ Create two global variables named file and err. Initialize file with an empty string and err with a Boolean false ▸ Create a try, except, else, finally structure The try part: Open the file data.csv storing the object into variable file Create a for loop to loop over the lines of the file Within the data file loop, create another for loop to loop over each character in each line Test for each character, when it is a comma, skip the character, otherwise calculate the sum of all numbers ➤ The except part: Test for a file not found exception Set the err variable to a Boolean true The else part: Display the sum as shown below > The finally part: Test the file variable, when it is not equal to an empty string, then close the file Test the err variable: If it is true, display a message "Program completed with errors" (see output below) If it is false, display a message "Program completed successfully without errors" (see output below) Test your program in two ways and provide two screenshots or both runs in one screenshot as shown below: Execute the program, it should complete with no errors and display the sum > Change the file name to data1.csv in your program and execute the program, it should now display the error message Command Prompt

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question
Create the following program: Read a data file (data.csv download from Canvas) in a try, except, else, finally structure and calculate the total of all numbers contained in the file.

- Create two global variables named `file` and `err`. Initialize `file` with an empty string and `err` with a Boolean false.
- Create a try, except, else, finally structure.
  - **The try part:**
    - Open the file `data.csv` storing the object into variable `file`.
    - Create a for loop to loop over the lines of the file.
    - Within the data file loop, create another for loop to loop over each character in each line.
    - Test for each character, when it is a comma, skip the character, otherwise calculate the sum of all numbers.
  - **The except part:**
    - Test for a file not found exception.
    - Set the `err` variable to a Boolean true.
  - **The else part:**
    - Display the sum as shown below.
  - **The finally part:**
    - Test the `file` variable, when it is not equal to an empty string, then close the file.
    - Test the `err` variable:
      - If it is true, display a message "Program completed with errors" (see output below).
      - If it is false, display a message "Program completed successfully without errors" (see output below).

Test your program in two ways and provide two screenshots or both runs in one screenshot as shown below:
- Execute the program, it should complete with no errors and display the sum.
- Change the file name to `data1.csv` in your program and execute the program, it should now display the error message.

**Graph/Diagram Explanation:**
The screenshot shows a command prompt window displaying the results of two program executions. In the first execution, the program calculates and outputs "The sum = 41" followed by "Program completed successfully without errors". In the second execution, the program outputs "Program completed with errors", indicating an issue, likely due to the renamed file.
Transcribed Image Text:Create the following program: Read a data file (data.csv download from Canvas) in a try, except, else, finally structure and calculate the total of all numbers contained in the file. - Create two global variables named `file` and `err`. Initialize `file` with an empty string and `err` with a Boolean false. - Create a try, except, else, finally structure. - **The try part:** - Open the file `data.csv` storing the object into variable `file`. - Create a for loop to loop over the lines of the file. - Within the data file loop, create another for loop to loop over each character in each line. - Test for each character, when it is a comma, skip the character, otherwise calculate the sum of all numbers. - **The except part:** - Test for a file not found exception. - Set the `err` variable to a Boolean true. - **The else part:** - Display the sum as shown below. - **The finally part:** - Test the `file` variable, when it is not equal to an empty string, then close the file. - Test the `err` variable: - If it is true, display a message "Program completed with errors" (see output below). - If it is false, display a message "Program completed successfully without errors" (see output below). Test your program in two ways and provide two screenshots or both runs in one screenshot as shown below: - Execute the program, it should complete with no errors and display the sum. - Change the file name to `data1.csv` in your program and execute the program, it should now display the error message. **Graph/Diagram Explanation:** The screenshot shows a command prompt window displaying the results of two program executions. In the first execution, the program calculates and outputs "The sum = 41" followed by "Program completed successfully without errors". In the second execution, the program outputs "Program completed with errors", indicating an issue, likely due to the renamed file.
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 5 steps with 4 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY