编程实现对一个元素全为数字的列表,求最大值、最小值(回炉笔记)
程序员文章站
2023-01-12 13:20:34
__author__ = 'zht' #!/usr/bin/env python # -*- coding: utf-8 -*- ''' #努力学习每一天 ''' import operator #方法1 a = [1,2,3,4,5,6,7,11,10,9,] i = 1 b = a[0] whi... ......
__author__ = 'zht' #!/usr/bin/env python # -*- coding: utf-8 -*- ''' #努力学习每一天 ''' import operator #方法1 a = [1,2,3,4,5,6,7,11,10,9,] i = 1 b = a[0] while i <= len(a): for k in a: if b >= k: pass else: b = k i +=1 print(b) #方法2 res = max(a) print(res) res = min(a) print(res)
上一篇: 开除
下一篇: 列表联系(回炉练习)