Question

(statistics.py) Write a program that reads data from the file provided, data.txt, into a list. Once...

(statistics.py) Write a program that reads data from the file provided, data.txt, into a list. Once the data are in a list, calculate and print the following:

   sum = 69.28
   mean = 3.46
   min = 0.19
   max = 8.29

You may use the Python built-ins, min(), max(), and sum(). Format the numbers using '.2f'.

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

file = open("data.txt")
lst = []
for x in file:
    lst.append(float(x.strip()))
print("sum = %.2f"%sum(lst))
print("mean = %.2f"%(sum(lst)/len(lst)))
print("min = %.2f"%min(lst))
print("max = %.2f"%max(lst))
Add a comment
Know the answer?
Add Answer to:
(statistics.py) Write a program that reads data from the file provided, data.txt, into a list. Once...
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
  • Write a Python program n_kids.py that reads the data from n_kids.txt, does some math, then displays...

    Write a Python program n_kids.py that reads the data from n_kids.txt, does some math, then displays the following: Total number of families: Total number of kids: Average number of kids per family: Maximum number of kids in a family: Minimum number of kids in a family: Extra credit (2 pts): write the above results to a different file (results.txt, not to the input file n_kids.txt) in addition to displaying them on the screen. Do not use built-in min and max...

  • Write a program to read the contents of data.txt file, and determine the smallest value (min),...

    Write a program to read the contents of data.txt file, and determine the smallest value (min), largest value (max), and the average value (ave). The minimum, maximum, and average values must be calculated in the function calc(). Remember to declare the stdlib.h library, so that you can use the atof function, which will convert the number in the text file into float number. Also, remember to check if there is an error opening the file or not. If there is...

  • write a python program that reads from a file, scores.txt, a list of test scores. the...

    write a python program that reads from a file, scores.txt, a list of test scores. the program should calculate the average of all the scores, and print to the screen. the program should also have a function, num_passing, that takes as a parameter the list or grades and returns the number of scores that are above 64.

  • Exercise 4 Data rotation Write a program in C that reads from a file INFILE (you...

    Exercise 4 Data rotation Write a program in C that reads from a file INFILE (you should create this file) a sequence of integer numbers. Consider that the length of the sequence is not knoun. Then, print to the file OUTFILE the sequence according to the following example: INFILE: 123456789 OUTFILE: 19 2 837465 The INFILE must be read only once!

  • 1. Write a C++ program that reads daily weather observation data from a file and writes...

    1. Write a C++ program that reads daily weather observation data from a file and writes monthly and annual summaries of the daily data to a file. a. The daily weather data will be contained in a file named wx_data.txt, with each line of the file representing the weather data for a single day. b. For each day, the date, precipitation amount, maximum temperature, and minimum temperature will be provided as tab-separated data with the following format: 20180101 0.02 37...

  • FUNCTIONS In this assignment, you will revisit reading data from a file, and use that data...

    FUNCTIONS In this assignment, you will revisit reading data from a file, and use that data as arguments (parameters) for a number of functions you will write. You will need to: Write and test a function square_each(nums) Where nums is a (Python) list of numbers. It modifies the list nums by squaring each entry and replacing its original value. You must modify the parameter, a return will not be allowed! Write and test a function sum_list(nums) Where nums is a...

  • Write a complete C program to get data from file name DATA.TXT one line at a...

    Write a complete C program to get data from file name DATA.TXT one line at a time until there is no more data in that file. The following is one sample line in DATA.TXT ( have as many record as you wish in DATA.TXT) Name     SSN                           quiz         mid         assignments      participation     final LISA         111-11-1111      100         100         100                           100                           100 Jack        222-22-2222      80            80            100                           90                              100 Note that the first line is no in DATA.txt. Your program should create...

  • 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

  • Topics: list, file input/output (Python) You will write a program that allows the user to read...

    Topics: list, file input/output (Python) You will write a program that allows the user to read grade data from a text file, view computed statistical values based on the data, and to save the computed statistics to a text file. You will use a list to store the data read in, and for computing the statistics. You must use functions. The data: The user has the option to load a data file. The data consists of integer values representing student...

  • In this assignment, you will revisit reading data from a file, and use that data as...

    In this assignment, you will revisit reading data from a file, and use that data as arguments (parameters) for a number of functions you will write. You will need to: Write and test a function square_each(nums) Where nums is a (Python) list of numbers. It modifies the list nums by squaring each entry and replacing its original value. You must modify the parameter, return will not be allowed! Write and test a function sum_list(nums) Where nums is a (Python) list...

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