Home>

Get an integer value from the standard input.
○ However, use repeat (while) so that you can enter as many items as you like.
If there is no input, exit.

  1. Create a function that displays the maximum, minimum, mean, median, and standard deviation of the acquired data.
code
import statistics
def F1 (A):
  print ("A:", A)
  print ("maximum value:", max (A))
  print ("minimum value:", min (A))
  print ("Arithmetic Mean:", statistics.mean (A))
  print ("median:", statistics.median (A))
  print ("biased standard deviation: {: .4f}". format (statistics.stdev (A)))
while True:
  C = input ("number:")
  if len (C) == 0:
     break
  C = int (A)

F1 (C)


When I entered the numbers 1,2,3, ... in this code, the error of len was broken, but the error occurred on the line of print ("maximum value", max (A)) n. I have. It was written as max () arg is an empty sequence. What can I do to fix this error?

  • Answer # 1

    import statistics
    def F1 (A):
      print ("A:", A)
      print ("maximum value:", max (A))
      print ("minimum value:", min (A))
      print ("Arithmetic Mean:", statistics.mean (A))
      print ("median:", statistics.median (A))
      print ("biased standard deviation: {: .4f}". format (statistics.stdev (A)))
    nums = []
    while True:
      C = input ("number:")
      if len (C) == 0:
         break
      C = int (C)
      nums.append (C)
    F1 (nums)