Question

a file containing a series of integers is named numbers.txt. Write a Python program that calculates...

a file containing a series of integers is named numbers.txt. Write a Python program that calculates the average of all the numbers stored in the file.

Sample Run
49.6

0 0
Add a comment Improve this question Transcribed image text
Answer #1
grades = []
try:
    fileName = "numbers.txt"
    with open(fileName, 'r') as f:
        for x in f:
            grades.append(float(x.strip()))
    s = 0
    for i in range(len(grades)):
        s += grades[i]
    print("Average =",(s/len(grades)))
except Exception:
    print("Exception occurred")

4
1
5
2
3

Add a comment
Know the answer?
Add Answer to:
a file containing a series of integers is named numbers.txt. Write a Python program that calculates...
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
  • Question 2: Assume that a text file containing a series of integers is named numbers.txt and...

    Question 2: Assume that a text file containing a series of integers is named numbers.txt and exists on the c:Temp. Write a program that reads all of the numbers stored in the file and calculates their total. In order to test this program, you may create a text file using notepad. No GUI is necessary. Name the program number.py

  • NEED PYTHON PROGRAM CODE FOR THIS QUESTION Average of numbers Assume that a file containing a...

    NEED PYTHON PROGRAM CODE FOR THIS QUESTION Average of numbers Assume that a file containing a series of integers is named numbers.dat and exists on the computer’s disk. Design a program that calculates the average of all the numbers stored in the file.

  • Write a Python named numbersread.py that uses a loop to read and process numbers.txt. The program...

    Write a Python named numbersread.py that uses a loop to read and process numbers.txt. The program should output all of the integers, one per line, and then output the total of the even integers and the total of the odd integers.

  • Starting out with python 4th edition Write program that lets the user enter in a file...

    Starting out with python 4th edition Write program that lets the user enter in a file name (numbers.txt) to read, keeps a running total of how many numbers are in the file, calculates and prints the average of all the numbers in the file. This must use a while loop that ends when end of file is reached. This program should include FileNotFoundError and ValueError exception handling. Sample output: Enter file name: numbers.txt There were 20 numbers in the file....

  • Shire MIS 102 Computer Logic Chagter 10 Fles Assume that a file containing a series of integers i...

    should be in c++ Shire MIS 102 Computer Logic Chagter 10 Fles Assume that a file containing a series of integers is named number dat and exist on the computer's disk Design a program that calculates the average of all the numbers stored in the file. Hint: Your program should contain a loop structure and a EOF to indicate the end of file. Chapter 11 Menu-Oriven Programs Design a program thet can be used to keep all of your friend's...

  • 1.Write a python program that writes a series of random numbers to a file named random.txt....

    1.Write a python program that writes a series of random numbers to a file named random.txt. Each random number should be in the range of 1 through 300. The application should let the user specify how many random numbers the file will hold. 2. Write another program that reads the random numbers from the random.txt file, displays the numbers, then displays the following data: I. The total of the numbers II. The number of random numbers read from the file

  • C++ 3. Write a program that reads integers from a file, sums the values and calculates...

    C++ 3. Write a program that reads integers from a file, sums the values and calculates the average. a. Write a value-returning function that opens an input file named in File txt. You may "hard-code" the file name, i.e., you do not need to ask the user for the file name. The function should check the file state of the input file and return a value indicating success or failure. Main should check the returned value and if the file...

  • Description: Create a program called numstat.py that reads a series of integer numbers from a file...

    Description: Create a program called numstat.py that reads a series of integer numbers from a file and determines and displays the name of file, sum of numbers, count of numbers, average of numbers, maximum value, minimum value, and range of values. Purpose: The purpose of this challenge is to provide experience working with numerical data in a file and generating summary information. Requirements: Create a program called numstat.py that reads a series of integer numbers from a file and determines...

  • Write a java program that creates a file called numbers.txt that uses the PrintWriter class. Write...

    Write a java program that creates a file called numbers.txt that uses the PrintWriter class. Write the odd numbers 1 to 99 into the file. Close the file. Using Scanner, open the numbers.txt file and read in the numbers. Add them all up and print the total. Close the file.

  • 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...

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