Initialize an array/list with five integers. Write a program to find the sumand average of these numbers
Question
Initialize an array/list with five integers. Write a program to find the sum and average of these numbers.
Solution
Sure, here is a simple Python program that initializes a list with five integers, calculates the sum and average of these numbers.
# Initialize a list with five integers
numbers = [10, 20, 30, 40, 50]
# Calculate the sum of the numbers
sum_of_numbers = sum(numbers)
# Calculate the average of the numbers
average_of_numbers = sum_of_numbers / len(numbers)
# Print the sum and average
print("Sum of the numbers: ", sum_of_numbers)
print("Average of the numbers: ", average_of_numbers)
In this program, we first initialize a list named numbers
with five integers. Then, we use the built-in sum()
function to calculate the sum of these numbers and store it in sum_of_numbers
. To calculate the average, we divide the sum by the number of elements in the list, which we get using len(numbers)
. Finally, we print the sum and average.
Similar Questions
code this in java using patterns: Specification: Read in integers until the user enters -1. If there was at least one integer, show the average value.
The average of 10 numbers is 7. If each number is multiplied by 12, then the average of the new set of numbers will be?Options7828419
20 numbers averaged to 40, if 25 and 55 are two numbers which are subtracted from the list, the new average become
evelop a Java program that calculates the average of three floating-pointnumbers and displays a grade based on the average.
Question 2What is the mean of the following list?1,2,4,5,34,1,32,4,34,2,1,3Please use a decimal point instead of a comma1 point
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.