HJ97 记负均正

思路:

step1:输入一个正整数n,输入n个整数;
step2:设置fu、zheng、count三个参数,便于后续计算;
step3:对n个整数进行遍历,如果<0,fu加一;如果>0,将数累加,并count计数;
step4:如果没有正数,则打印(fu,0.0);否则,算出均值,打印(fu,res)

代码如下:

n=int(input())
nums=map(int,input().split())
fu = 0
zheng = 0
count = 0
for i in nums:
    if i < 0:
        fu += 1
    elif i > 0:
        zheng += i 
        count += 1
if count == 0:
    print(fu,0.0)
else:
    res = round(zheng / count , 1)
    print(fu,res)