统计年龄人数
从键盘输入一组年龄存入列表中,统计35岁(含35岁)以下年龄段、35岁到59(含59岁)年
龄段和60岁以上年龄段的人数,并输出。
输入格式:输入一行以空格分隔的年龄值。
输出格式:输出各年龄段人数,参看输入输出示例。
输入样例:12 67 55 70 45 40
输出样例:less than and equal 35:1
35 to 60:3
bigger than and equal 60:2
count1 =0
count2 =0
count3 =0
lst = list(map(int, input().split()))
for i in lst:
if i>=0 and i<=35:
count1+=1
elif i>=35 and i<=60:
count2+=1
else:
count3+=1
print('less than and equal 35:{}\n35 to 60:{}\nbigger than and equal 60:{}'.format(count1,count2,count3))
dic = {}
s = ['less than and equal 35','35 to 60','bigger than and equal 60']
n = list(map(int, input('输入一行以空格分隔的年龄值:').split()))
for i in n:
if i<=35:
dic[s[0]] = dic.get(s[0],0)+1
elif 35<i<=59:
dic[s[1]] = dic.get(s[1],0)+1
else:
dic[s[2]] = dic.get(s[2],0)+1
for i in s:
print(':'.join([i,str(dic[i])]))
连提个问题都要杀人诛心吗(35岁)