Python Exercise: Calculate the sum and average of n integer numbers
42. Sum and Average of n Integers
Write a Python program to calculate the sum and average of n integer numbers (input from the user). Input 0 to finish.
Pictorial Presentation:

Sample Solution-1:
Python Code:
Sample Output:
Input some integers to calculate their sum and average. Input 0 to exit . 15 16 12 0 Average and Sum of the above numbers are: 14.333333333333334 43.0
Flowchart :

Sample Solution-2:
Calculates the average of two or more numbers.
Use sum() to sum all of the args provided, divide by len().
Python Code:
Sample Output:
2.5 2.0
Flowchart :

For more Practice: Solve these Related Problems:
- Write a Python program to repeatedly accept integers from the user until 0 is entered, then output their sum and average.
- Write a Python program to accumulate a list of integers entered by the user and compute both total and mean when the input terminates.
- Write a Python program to implement a loop that reads integers until 0 and then calculates and prints the sum and average.
- Write a Python program to use a while loop to collect integers from user input, then compute the sum and average after the loop exits on 0.
Go to:
Previous: Write a Python program to get next day of a given date.
Next: Write a Python program to create the multiplication table (from 1 to 10) of a number.
Python Code Editor:
Have another way to solve this solution? Contribute your code (and comments) through Disqus.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.