This Phyton: In this lab, you will write a program that reads integers from a file “data.txt” into a list, print the list and the sum of the numbers in the list.  The file contains one integer per line.  You are not required to do any exception handling.  Your program should not prompt the user for any input.  The input file is “data.txt”. First, create a file “data.txt” and put the numbers add the numbers 3, 1, 5, 2 into it, one number per line as shown in the sample “data.txt” file below. Sample “data.txt” file 3 1 5 2   Then, write the following functions: read_numbers(filename) Read numbers from the given file and return a list of contains the numbers from the file. compute_sum(numbers) Compute the sum of the given the list numbers.  Do not use the built-in sum function. main() Read numbers from the file “data.txt”, print the list, and compute the sum and print it.  Main will use the two functions above to get the job done.   Sample run: [3, 1, 5, 2] sum= 11

EBK JAVA PROGRAMMING
9th Edition
ISBN:9781337671385
Author:FARRELL
Publisher:FARRELL
Chapter12: Exception Handling
Section: Chapter Questions
Problem 9PE
icon
Related questions
Question

This Phyton:

In this lab, you will write a program that reads integers from a file “data.txt” into a list, print the list and the sum of the numbers in the list.  The file contains one integer per line.  You are not required to do any exception handling.  Your program should not prompt the user for any input.  The input file is “data.txt”.

First, create a file “data.txt” and put the numbers add the numbers 3, 1, 5, 2 into it, one number per line as shown in the sample “data.txt” file below.

Sample “data.txt” file

3

1

5

2

 

Then, write the following functions:

read_numbers(filename)

Read numbers from the given file and return a list of contains the numbers from the file.

compute_sum(numbers)

Compute the sum of the given the list numbers.  Do not use the built-in sum function.

main()

Read numbers from the file “data.txt”, print the list, and compute the sum and print it.  Main will use the two functions above to get the job done.

 

Sample run:

[3, 1, 5, 2]

sum= 11

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 3 images

Blurred answer
Knowledge Booster
Exception Handling Keywords
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning