Write a program in Python to find the average of 4 numbers: ❌Don't spam❌
Answers
Answered by
4
Python Program to Calculate the Average of Numbers in a Given...
- Take the number of elements to be stored in the list as input.
- Use a for loop to input elements into the list.
- Calculate the total sum of elements in the list.
- Divide the sum by total number of elements in the list.
- Exit.
(or)
Calculate the sum and average of a given list in Python.Let see you have a list of numbers and you want to calculate the sum of numbers present in the list.
- All you need to do is to iterate a list using a for loop and add each number to a sum variable.
- To calculate the average divide the sum by the length of a given list(total numbers in a list.
Let see this with an example.
Program 1:
sum = 0
list = [11,22,33,44,55,66,77]
for num in list:
sum = sum +num
average = sum / len(list)
print ("sum of list element is : ", sum)
print ("Average of list element is ", average )
hope it helps
Similar questions