python3 练习题100例 (十八)托儿所问题

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""练习十八:某托儿所有大、中、小三个班级,其儿童月龄分别用如下 三个列表表示:
x = [18, 18, 19, 19, 24, 23, 22, 22, 21, 20, 19, 22, 23, 24, 24]
y = [25, 28, 30, 29, 28, 27, 27, 25, 26, 25, 26, 27, 24]
z = [31, 33, 32, 32, 32, 34, 34, 35, 36, 35, 36, 37, 30, 30]
计算托儿所儿童平均月齡,最大月龄,最小月龄,同时找出月龄为30的儿童数量,月龄最大的前3名儿童的月齡为多少。"""

__author__ = 'Fan Lijun'

x = [18, 18, 19, 19, 24, 23, 22, 22, 21, 20, 19, 22, 23, 24, 24]
y = [25, 28, 30, 29, 28, 27, 27, 25, 26, 25, 26, 27, 24]
z = [31, 33, 32, 32, 32, 34, 34, 35, 36, 35, 36, 37, 30, 30]
lst = x + y + z
print('托儿所儿童平均月龄为{:.2f}'.format(sum(lst)/len(lst)))
print(f'托儿所的最大月龄为{max(lst)}')
print(f'托儿所的最小月龄为{min(lst)}')
print(f'月龄为30的儿童有{lst.count(30)}个')

x = max(lst)
lst.remove(x)
y = max(lst)
lst.remove(y)
z = max(lst)
print(f'月龄最大的三个儿童的月龄分别是{x, y, z}')

 

posted on 2018-11-28 09:31  daxia5398  阅读(213)  评论(0编辑  收藏  举报

导航