पायथन n तत्वों की संख्या की गणना के लिए योग फ़ंक्शन प्रदान करता है। यहां हम इस फ़ंक्शन का उपयोग करते हैं और फिर औसत की गणना करते हैं।
एल्गोरिदम
Step 1: input “size of the list” Step 2: input “Element” Step 3: using sum function calculate summation of all numbers. Step 4: calculate average.
उदाहरण कोड
# Average of a list
A=list()
n=int(input("Enter the size of the List ::"))
print("Enter the number ::")
for i in range(int(n)):
k=int(input(""))
A.append(int(k))
sm=sum(A)
avg=sm/n
print("SUM = ",sm)
print("AVERAGE = ",avg)
आउटपुट
Enter the size of the List ::5 Enter the number:: 10 20 30 40 50 SUM = 150 AVERAGE = 30.0