logo CodeStepByStep logo

even_numbers

Language/Type: Python file input %

Write a function named even_numbers that accepts a file name as a parameter. Your function should read input from the file which contains a series of integers. Report various statistics about the integers to the console. Report the total number of numbers, the sum of the numbers, the count of even numbers and the percent of even numbers. For example, if the input file numbers.txt contains the following text:

5 7 2 8
9 10 12
98 7
14
20 22

Then the call even_numbers("numbers.txt") should produce the following output:

12 numbers, sum = 214
8 evens (66.67%)
Function: Write a Python function as described, not a complete program.

You must log in before you can solve this problem.

Log In

Need help?

Stuck on an exercise? Contact your TA or instructor.

If something seems wrong with our site, please

Is there a problem? Contact us.