Answer to Question #263334 in Python for anji

Question #263334

Average of Given Numbers


You are given space-separated integers as input. Write a program to print the average of the given numbers.


Input


The first line of input contains space-separated integers.


Output


The output should be a float value rounded up to two decimal places.


Explanation


In the example, input is


1, 0, 2, 5, 9, 8. The sum of all numbers present in the list is 25, and their average is 25/6.


So, the output should be


4.17.


Sample Input 1

1 0 2 5 9 8

Sample Output 1

4.17

Sample Input 2

1 2 3 4 5

Sample Output 2

3.0


1
Expert's answer
2021-11-09T17:46:04-0500
numbers  = input("Enter numbers to get average(sepeparated by [space]): ")
numbers = numbers.split(" ")
numbers_list = []
for number in numbers:
    try:
        numbers_list.append(int(number))  
    except:
        pass
sum = 0
for number in numbers_list:
    sum += number


print("Average: {}".format(sum/len(numbers_list)))

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS