Question: Please help me write a code that satisfies these conditions using Python and include comments since I am very new to coding. You will revisit

Please help me write a code that satisfies these conditions using Python and include comments since I am very new to coding.

You will revisit reading data from a file, and use that data as arguments (parameters) for a number functions you will write.

You will need to:

  1. 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!
  2. Write and test a function sum_list(nums)
    • Where nums is a (Python) list of numbers. It returns the sum of the numbers in passed-in the list.
  3. Write and test a function to_numbers(str_list)
    • Where str_list is a list of strings, each of which represents a number. Modify each entry in the list by converting it to a number. You can choose to use return the list, or just modify str_list in-place, similar to #1, above.
  4. Write and test a function main()
    • Take the previous three functions and construct a main() function that will call these functions properly. The program computes the sum of the squares of numbers read from a file. Your program should prompt for a file name and print out the sum of the squares of the values in the file. Hint: use readlines()

Example files of numbers to read in:

File #1: 54 63 63 42 83 42 22 27 88 52

File #2: 54,63,63,42,83,42,22,27,88,52

What the ouput should look like (example):

This program computes the sum of the squares of numbers read from a file. Please enter the file name: numbers_csv.txt The sum of the squares of the numbers in the file is 32932.0

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!