输入10个数据,统计其中正数、负数、0,各有多少个
使用Python进行回答
# 输入 10 个整数,统计其中正数、负数和零的个数
num = 1
positive = 0
negative = 0
zero = 0
while num <= 10:
a = int(input())
num += 1
if a > 0:
positive += 1
elif a < 0:
negative += 1
else:
zero += 1
print(positive)
print(negative)
print(zero)
有帮助的话采纳一下哦!
positive_num = []
negative_num = []
others = []
for i in range(1,11):
num = int( input('请输入10个数,现在开始第{}个:'.format(i)) )
if num > 0:
positive_num.append(num)
elif num < 0 :
negative_num.append(num)
else:
others.append(num)
print('10个数字中,正数有{}个,负数有{}个,0有{}个'.format( len(positive_num),len(negative_num),len(others) ))