AlimusSifar

Running Average Again - Toph.co - Beginner

Mar 9th, 2020
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.43 KB | None | 0 0
  1. n = int(input())                    # takes n = total number of inputs
  2. tokens = input().split()            # takes n inputs in to an Array
  3. sum = 0.0                           # variable to store the sums of inputs
  4. # 1 loop to run the average
  5. i = 1
  6. while (i <= n):
  7.     sum = sum + int(tokens[i - 1])  # updates the sum with the new inputs
  8.     # Formatted printing for matching Output
  9.     if (sum % i == 0):
  10.         print('%.0f' % (sum / i))
  11.     else:
  12.         print('%.10f' % (sum / i))
  13.     i = i + 1
Add Comment
Please, Sign In to add comment