题解 | #记负均正II#
记负均正II
https://www.nowcoder.com/practice/64f6f222499c4c94b338e588592b6a62
import sys # 1.获取所有数字,并存到list1 list1=[] for line in sys.stdin: a = line.split() list1.append(a[0]) # 2.初始化count和sum,如果是负数,统计负数数字个数,非负数,就把所有非数组值累加 count=0 sum=0 for i in list1: if int(i)<0: count=count+1 else: sum=sum+int(i) # 3.非负数总和结果除以非负数个数 avgnum=sum/(len(list1)-count) # 4.返回结果,其中非负数平均值使用round保留指定小数 print(count) print(round(avgnum,1))