代码展示:
N = eval(input())
data = input().split()
# print('N =',N)
# print("data =",data)
K = 0
Y = 0
for item in data:
try:
value = eval(item)
except:
print('ERROR: {} is not a legal number'.format(item))
continue
if (type(value) == int or type(value) == float) and (-1000 <= value <= 1000):
if type(value) == int:
Y += value
K += 1
elif type(value) == float and len(str(value).split('.')[-1])<3:
Y += value
K += 1
else:
print('ERROR: {} is not a legal number'.format(item))
else:
print('ERROR: {} is not a legal number'.format(item))
if K == 0:
print('The average of 0 numbers is Undefined')
else:
print('The average of {0} numbers is {1:<.2f}'.format(K,(Y/K)))
测评结果: