Answered step by step
Verified Expert Solution
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:
- 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 of numbers. It returns the sum of the numbers in passed-in the list.
- 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.
- 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
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started