Question

a. Provide me with your code file, output file and the text file. 1. Create a...

a. Provide me with your code file, output file and the text file.

1. Create a file with a series of integers. Save it as numbers. txt. Write a program that reads all the numbers and calculates their sum .

2. Create a file having different integers than the first one. Save it as numbers1. txt . Write a program that reads all the number and calculates their average.

Important: The two files that you are creating will contain different numbers.

IN PYTHON PLEASE

0 0
Add a comment Improve this question Transcribed image text
Answer #1

program 1:

======================================

with open("numbers.txt") as file1:
    lst = file1.readlines()
  
    newList=[]
    for i in lst:
        newList.append(int(i.strip()))

    sum=0
    for i in newList:
        sum += i

    print("Total: ",sum)

   ===================================

file1 numbers.txt

55
5
87
95
5
62
89
32
48
866
9965
78
963
7824
87
=======================================

//output

PS D:\LAB\HomeworkLib\python file read> py .\Calculate.py Total: 20261 PS D:\LAB\HomeworkLib\python file read> I

====================================

program2

with open("numbers1.txt") as file1:
    lst = file1.readlines()
  
    newList=[]
    for i in lst:
        newList.append(int(i.strip()))

    sum=0
    for i in newList:
        sum += i

    avg = sum/len(newList)
    print("Average :",round(avg,2))


==============================================

file2 numbers1.txt

12
34
56
78
4
46
34
23
45
23
4
111324
34
46
23
35
4

===========================================

//output2

PS D:\LAB\HomeworkLib\python file read> py . \Calculate1.py Average : 6577.94 PS D:\LAB\HomeworkLib\python file read> |

========================================================

This is the problem as per your requirement

please appreciate my effort by hit like button

and comment below in case having any doubt

Add a comment
Know the answer?
Add Answer to:
a. Provide me with your code file, output file and the text file. 1. Create a...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT