- 3

How to find average of a series of number entered by a user

How do I find the average of a series of a number entered by a user. The program should first prompt the user for how many numbers contained in the series . Note: the average should always be a float, even if the user inputs all integer

7th Feb 2021, 9:23 AM
klisco1
6 Respuestas
+ 6
Why do you need to tell the computer how many numbers will be entered? The computer can count. nums = input().split() print(sum(int(n) for n in nums) / len(nums))
7th Feb 2021, 9:56 AM
David Ashton
David Ashton - avatar
+ 4
Average = Sum of observation / Total no. of observation Though it depends on how the input will look like: If the input is like this: 2.0 3.1 1.2 1.5 Then you can use .split() to split string into list and use list comprehension to convert each element to float.
7th Feb 2021, 9:29 AM
noteve
noteve - avatar
+ 2
initialize a count and a total variables to zero loop while user give entry: add user input casted to float to total increment count print average = total/count
7th Feb 2021, 9:32 AM
visph
visph - avatar
- 3
please be more specific, show an example
7th Feb 2021, 9:31 AM
klisco1