Average of Given Numbers
You are given space-separated integers as input. Write a program to print the average of the given numbers.
The first line of input contains space-separated integers.
The output should be a float value rounded up to two decimal places.
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.
#Python 3.9.5
def get_numbers():
list = [int(x) for x in input('Enter sequence of numbers: ').split(' ')]
return list
def get_awerage(list):
awerage = sum(list)/len(list)
return awerage
def main():
list = get_numbers()
print('Awerage from the list: ', round(get_awerage(list), 2))
if __name__ == "__main__":
main()
Comments
Leave a comment