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
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 |
Trending now
This is a popular solution!
Step by step
Solved in 4 steps with 3 images