首先输入要输入的整数个数n,然后输入n个整数。输出为n个整数中负数的个数,和所有正整数的平均值,结果保留一位小数。
0即不是正整数,也不是负数,不计入计算。如果没有正数,则平均值为0。
数据范围: ,输入的整数都满足
首先输入一个正整数n,
然后输入n个整数。
输出负数的个数,和所有正整数的平均值。
11 1 2 3 4 5 6 7 8 9 0 -1
1 5.0
3 0 0 0
0 0.0
n = int(input()) ls = list(map(int,input().split())) sums = 0 nums = 0 nums1 = ls.count(0) for i in ls: if i > 0: sums += i elif i < 0: nums += 1 if nums + nums1 == n: print(nums,0.0) else: averge = round(sums/(n-nums-nums1),1) print(nums,averge,end=' ')
while True: try: n = int(input()) list1 = input().split(' ') # print(n,list1) count1 = 0 count2 = 0 sum1 = 0 for i in range(n): if list1[i] < '0': count1 += 1 elif list1[i] > '0': sum1 += int(list1[i]) count2 += 1 if count2 != 0: sum1 = sum1/count2 print(f'{count1} {sum1:.1f}') except: break
n=input() l=list(map(int,input().split(' '))) count_fu=0 count_zheng=0 add=0 avg=0 for i in l: if i<0: count_fu+=1 elif i>0: count_zheng+=1 add+=i if count_zheng==0: avg=0.0 else: avg=add/count_zheng print(count_fu,"%.1f"%avg)
n = int(input()) num_lst = list(map(int, input().split())) pos_num, neg_num, SUM = 0, 0, 0 for i in num_lst: if i > 0: pos_num += 1 SUM += i elif i < 0: neg_num += 1 print(str(neg_num)+' 0.0') if pos_num == 0 else print(str(neg_num)+' '+str(round(SUM/pos_num, 1)))
n = int(input()) num = list(map(int,input().split())) z =[] f = [] tol = 0 avg = 0 for i in range(len(num)): if num[i] >0: z.append(num[i]) elif num[i] <0: f.append(num[i]) for j in range(len(z)): tol +=z[j] if len(z) == 0: avg =0 elif len(z) !=0: avg = tol / len(z) print(len(f),'%.1f'% (avg))
def main(): while True: try: n=int(input().strip()) task=list(map(int,input().strip().split(' '))) task_right=[item for item in task if item >0] task_left=[item for item in task if item <0] print(len(task_left),end=' ') if len(task_right)==0: print(0.0) else: aver=sum(task_right)/len(task_right) print(f'{aver:.1f}') except EOFError as e: break main()