Devin Dahlberg

Python: Assignment Six

#Write a program that reads the attached file numbers.txt and displays the sum and average of numbers stored in the file

#Open file numbers.txt
myfile = open('numbers.txt', 'r')

#Read first line of numbers.txt
line = myfile.readline()


#Continue process while creating sum and average.
add = 0
repetitions = 0
while line != '':
    number = int(line)
    add = add + number
    line = myfile.readline()
    repetitions = repetitions + 1

avg =  add / repetitions

print(f"The sum of the numbers in the attached file is {add}. The average of the numbers attached is {avg}")

myfile.close()

numbers.txt content:

100

200

300

400

500

600

CH6P1