# Python Example – Write a Python program to calculate the sum and average of n integer numbers

Hits: 260 # (Python Example for Citizen Data Scientist & Business Analyst)

Write a Python program to calculate the sum and average of n integer numbers (input from the user). Input 0 to finish.

Sample Solution:

Python Code:

``````
print("Input some integers to calculate their sum and average. Input 0 to exit.")

count = 0
sum = 0.0
number = 1

while number != 0:
number = int(input(""))
sum = sum + number
count += 1

if count == 0:
print("Input some numbers")
else:
print("Average and Sum of the above numbers are: ", sum / (count-1), sum)
``````

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```

## Write a Python program to calculate the sum and average of n integer numbers

#### Free Machine Learning & Data Science Coding Tutorials in Python & R for Beginners. Subscribe @ Western Australian Center for Applied Machine Learning & Data Science. ```