题解 | #记负均正II#
记负均正II
https://www.nowcoder.com/practice/64f6f222499c4c94b338e588592b6a62
''' # 报错:EOF when reading a line end of file # 尝试从文件/输入流读取数据时,遇到文件结束符(EOF),没有读取到任何数据。 cnt_neg=0 cnt_nonneg=0 sum_nonneg=0 n=input() while n: n=int(n) if n<0: cnt_neg += 1 else: cnt_nonneg += 1 sum_nonneg += n n=input() if cnt_nonneg==0: print(cnt_neg,0.0) else: print(cnt_neg,round(sum_nonneg/cnt_nonneg,1)) ''' # 可以利用报错,遇到报错时输出结果 try except try: cnt_neg=0 cnt_nonneg=0 sum_nonneg=0 n=input() while n: n=int(n) if n<0: cnt_neg += 1 else: cnt_nonneg += 1 sum_nonneg += n n=input() except: print(cnt_neg) if cnt_nonneg==0: print('%.1f'%(0)) else: print('%.1f'%(sum_nonneg/cnt_nonneg))