Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a function file_sums() that has two parameters, say, infile and outfile, that are bound to file names. Each line in infile has one or

Write a function file_sums() that has two parameters, say, infile and outfile, that are bound to file names. Each line in infile has one or more integers separated by whitespace. This function writes as a line to outfile the sum of the integers on the corresponding line of infile. Open both files in a with statement. Use a list comprehension to convert the split line into a list of integers. Note that function sum(), passed a list of numbers, returns the sum of those numbers. Recall that file method write() takes a single, string argument; that argument must end with a new line (use ' ') for what is written to be a complete line (so that what is written next is on the following line). For example, if the contents of the input file data.txt (available from the assignment page, and which you should use as a test file) are 3 12 72 32 54 29 78 31 28 9 7 83 then the contents of the output file become 87 86 29 146 90

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

Database Design For Mere Mortals

Authors: Michael J Hernandez

4th Edition

978-0136788041

More Books

Students also viewed these Databases questions