Tuesday, January 4, 2022

How to store sample of elements in a List using For loop in Python Program

Python Program to store elements, finding Sum and Average of elements of the List
# Enter the elements with spaces to store in List
list1 = input('Enter list elements: ').split(' ')
sample = [int(i) for i in list1]
total = 0
avg = 0

for j in sample:
    print(j)
    total = total+j
print('The Total of Sample is: ', total)

n = len(sample)
avg = total/n
print('The Average of the Sample is: ', avg)

# ------------------------------------------------------------------------------------------------------------------------ #
Input:
Enter list elements: 10 20 30 40 50

Output:
10
20
30
40
50
The Total of Sample is:  150
The Average of the Sample is:  30.0
#--------------------------------------------------------------Thanks--------------------------------------------------------------#

No comments:

Post a Comment

Hi User, Thank You for visiting My Blog. Please post your genuine Feedback or comments only related to this Blog Posts. Please do not post any Spam comments or Advertising kind of comments which will be Ignored.