Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Data Management Databases And Organizations

Authors: Richard T. Watson

3rd Edition

0471418455, 978-0471418450

More Books

Students also viewed these Databases questions

Question

b. Explain how you initially felt about the communication.

Answered: 1 week ago

Question

3. Identify the methods used within each of the three approaches.

Answered: 1 week ago

Question

a. When did your ancestors come to the United States?

Answered: 1 week ago