一、题目
二、示例
三、代码
negative = 0
nonnegative = []
while True:
try:
shuru = int(input())
if shuru >= 0:
nonnegative.append(shuru)
else:
negative += 1
except:
print(negative)
if len(nonnegative) > 0:
print('%.1f' % (sum(nonnegative) / len(nonnegative)))
else:
print('0.0')
break
四、算法说明
与《HJ97 记负均正》类似,多了一步判断非负数的个数是否大于0.
胡萝卜
2022年1月9日13:32:35
我不知道将去向何方,但我已在路上! |
---|
时光匆匆,虽未曾谋面,却相遇于斯,实在是莫大的缘分,感谢您的到访 ! |