Home>

### processing using the len function when an integer value is obtained from python standard input

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, it ends.
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 = int (input ("number:"))
if len (C) == 0:
break
F1 (C)``````

In the above code, if you enter the numbers 1,2,3 ..., an error will occur with if len (c) == 0 :. TypeError: object of type'int' has no len () is displayed. Please tell me what and how to fix this error.

• Answer # 1

This is because the length of the character string is checked with len after converting to an integer.
To determine the end of input based on the length of the character string, the length of the character string should be checked and then converted to a numerical value.
Example)

`````` K = input ("number:")
if len (K) == 0:
break
C = int (K)``````

• Answer # 2

If you want to detect no input, take len in the string
After doing this check, I wondered if I should convert to an integer