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. If you wish, please share your genuine Feedback or comments only related to this Blog Posts. It is my humble request that, please do not post any Spam comments or Advertising kind of comments, which will be Ignored.

Featured Post from this Blog

How to compare Current Snapshot Data with Previous Snapshot in Power BI

How to Dynamically compare two Snapshots Data in Power BI Scenario: Suppose we have a sample Sales data, which is stored with Monthly Snapsh...

Popular Posts from this Blog