解题思路:
1)定义4个count计数器
2)输出%:'%.2f%%'%n
注意事项:
参考代码:
n=int(input()) #病人数目 ages=list(map(int,input().split())) #将病人患病年龄打包为整型数组 count1=0 #初始化4个计数器,用于统计各年龄段的患病人数 count2=0 count3=0 count4=0 for i in ages: #遍历年龄,落在对应年龄段则加1 if i>=0 and i<=18: count1+=1 elif i>=19 and i<=35: count2+=1 elif i>=36 and i<=60: count3+=1 elif i>=61: count4+=1 ls=[count1,count2,count3,count4] #创建数组 for j in ls: #遍历各年龄段患病人数的比例 print('%.2f%%'%(100*(j/n)))
0.0分
2 人评分
C语言程序设计教程(第三版)课后习题5.6 (C语言代码)浏览:850 |
【亲和数】 (C语言代码)浏览:501 |
WU-格式化数据输出 (C++代码)浏览:1194 |
三角形 (C++代码)递归(存在大量重复计算,容易出现时间超限)浏览:774 |
1017题解浏览:585 |
sizeof的大作用 (C语言代码)浏览:1448 |
判定字符位置 (C语言代码)浏览:792 |
数列问题 (C语言代码)浏览:1019 |
小O的图案 (C语言代码)浏览:912 |
简单的a+b (C语言代码)浏览:434 |