Knowee
Questions
Features
Study Tools

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 sumand average of these numbers

🧐 Not the exact question you are looking for?Go ask a question

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.

This problem has been solved

Similar Questions

Write a Program to Find the average of all Prime Numbers from a Given Array?

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

Single File Programming QuestionProblem StatementMithun is developing a program for a data collection tool that allows the user to input a series of positive integers until they enter a negative value. The program should dynamically allocate memory for an integer array to store these numbers using the new operator. The program should then calculate and display the sum and average of the entered integers. Write a program to accomplish this task.Note: This kind of question will help in clearing HCL recruitment.Input format :The input consists of positive integers separated by a space. It continues until a negative value is entered.Output format :The first line of the output displays the entered numbers.The second line displays the sum of the numbers.The third line displays the average of the entered numbers.Refer to the sample output for formatting specifications.Code constraints :numbers > 0Maximum number <=100Sample test cases :Input 1 :1 2 3 4 5 6 -1Output 1 :Numbers entered: 1 2 3 4 5 6 Sum of entered numbers: 21Average of entered numbers: 3.50Input 2 :10 20 30 40 50 60 70 80 90 100 -4Output 2 :Numbers entered: 10 20 30 40 50 60 70 80 90 100 Sum of entered numbers: 550Average of entered numbers: 55.00Note :The program will be evaluated only after the “Submit Code” is clicked.Extra spaces and new line characters in the program output will result in the failure of the test case.

Q4 - Average Of all Array ElementsWrite a Program to Find the average of all elements in a Given Array?Constraints:Input          :- First Line of Input Consists of One Integer Value (Array Size).                     Second Line of Input Consists of few Integer Values Separated by Space (Array Elements).Output        :- Print the Average of All the Array Elements.Constraints  :- Array Size must be Greater then 0 or else Print "Invalid ArRay Size.".                      Print the Average value upto 5 Decimal points.Example:Input 1  :    6                  10 02 20 21 11 54Output 1:    Average of Given Array Elements is 19.66666. Input 2  :    4                  1 2 3 0Output 2:    Average of Given Array Elements is 1.50000.Explanation:Input 1  :    6                  10 02 20 21 11 54Output 1:    19.66666Explanation:                  Sum = 10 + 02 + 20 + 21 + 11 + 54                          = 118                  Average = 118 / 6 = 19.66666. Input 2  :    4                  1 2 3 0Output 2:    1.50000.Explanation:                  Sum = 1 + 2 + 3 + 0                          = 6                  Average = 6 / 4 = 1.55555.

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

1/3

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.