Question

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.

0 0
Add a comment Improve this question Transcribed image text
Answer #1
try:
    with open('numbers.dat') as f:
        total, count = 0, 0
        for line in f:
            words = line.strip().split()
            for word in words:
                total += int(word)
                count += 1
        print("Average of all the numbers in numbers.dat is", total / count)
except FileNotFoundError:
    print('numbers.dat does not exists!')
Add a comment
Know the answer?
Add Answer to:
NEED PYTHON PROGRAM CODE FOR THIS QUESTION Average of numbers Assume that a file containing 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
  • 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

  • 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

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

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

  • In Python Provide me with your code file, output file and the text file Create a...

    In Python Provide me with your code file, output file and the text file 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.

  • Write a PYTHON program that reads a file (prompt user for the input file name) containing...

    Write a PYTHON program that reads a file (prompt user for the input file name) containing two columns of floating-point numbers (Use split). Print the average of each column. Use the following data forthe input file: 1   0.5 2   0.5 3   0.5 4   0.5 The output should be:    The averages are 2.50 and 0.5. a)   Your code with comments b)   A screenshot of the execution Version 3.7.2

  • 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

  • USING PYTHON PROGRAMMING LANGUAGE 15. Write code to open a file named data.txt, which contains 3...

    USING PYTHON PROGRAMMING LANGUAGE 15. Write code to open a file named data.txt, which contains 3 numbers, and print the sum of those numbers to the console 16. Write code that opens a file named words.txt containing an essay, and the prints out the SECOND word in the file to the console

  • Write a program **(IN C)** that displays all the phone numbers in a file that match the area code...

    Write a program **(IN C)** that displays all the phone numbers in a file that match the area code that the user is searching for. The program prompts the user to enter the phone number and the name of a file. The program writes the matching phone numbers to the output file. For example, Enter the file name: phone_numbers.txt Enter the area code: 813 Output: encoded words are written to file: 813_phone_numbers.txt The program reads the content of the file...

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

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