logo CodeStepByStep logo


Language/Type: Python input loops cumulative algorithms

Write a function named print_average that repeatedly prompts the user for numbers. Once any number less than zero is typed, the average of all non-negative numbers typed is displayed. Display the average as a real number, and do not round it. The following is one example log of execution for your function:

Type a number: 7
Type a number: 4
Type a number: 16
Type a number: -4
Average was 9.0

If the first number typed is negative, do not print an average. For example:

Type a number: -2
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.