In Statistics, Mean (average) is a common term used to analyze the data. Thus, we should know how to program this Statistical term using Python. For this, write a Python program to calculate the sum and average (Mean) of n integer numbers (input from the user). Input 0 to finish the list.Sample:Input some integers to calculate their sum and average. Input 0 to exit .1516120Average and Sum of the above numbers are: 14.333333333333334 43.0
Question
In Statistics, Mean (average) is a common term used to analyze the data. Thus, we should know how to program this Statistical term using Python. For this, write a Python program to calculate the sum and average (Mean) of n integer numbers (input from the user). Input 0 to finish the list.Sample:Input some integers to calculate their sum and average. Input 0 to exit .1516120Average and Sum of the above numbers are: 14.333333333333334 43.0
Solution
Sure, here is a simple Python program that calculates the sum and average of n integer numbers. The program will stop taking inputs when the user enters 0.
# Initialize variables
sum = 0
count = 0
while True:
# Take input from user
num = int(input("Enter an integer (input 0 to exit): "))
# Check if input is 0
if num == 0:
break
# Add input to sum
sum += num
# Increment count
count += 1
# Calculate average
average = sum / count
# Print sum and average
print("Sum of the numbers: ", sum)
print("Average of the numbers: ", average)
In this program, we use a while loop to continuously take inputs from the user until they enter 0. For each input, we add it to the sum and increment the count. After the loop, we calculate the average by dividing the sum by the count, and then print the sum and average.
Similar Questions
Initialize an array/list with five integers. Write a program to find the sumand average of these n
def subroutine( n ): while n > 0: print (n,) n = n - 1Question 1Select one:a.Counts from 10 down to 0 and displays each numberb.Counts from n down to 1 and displays each numberc.Calculates the sum of n numbers greater than 0d.Calculates the mean of n
Problem StatementWrite a program to find the average of N numbers. Print the average in 2 digit precision DO NOT USE ARRAYInput FormatFirst line consist of a single integer - 'N'Second line consist of N space separated integersOutput FormatDisplay the average of N numbersSample Input51 2 3 4 5Sample Output3.00
What is the average value of the following Python code snippet?>>>marks1 = 40>>>marks2 = 50>>>avg = (marks1 + marks2) / 2Options45.145.055.055.1
What function can be used in Google Sheets to find the average of a range of numbers
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.