提问:如何使用Python语言实习如下功能
网友回答:
代码如下:
str1=input("请输入年龄(用逗号分隔):")
listone=str1.split(',')
a=0;b=0;c=0;d=0
for x in listone:
i=int(x)
if i>18 and i<=23:
a=a+1
elif i>=16 and i<=18:
b=b+1
elif i >=13 and i<=15:
c=c+1
elif i>=7 and i<=12:
d=d+1
print("大学:",a)
print("高中:",b)
print("初中:",c)
print("小学:",d)