python 列表求最大值_Python找出列表中的最大数和最小数
Python找出列表中数字的最大值和最小值思路:先使用冒泡排序将列表中的数字从小到大依次排序取出数组首元素和尾元素运行结果:源代码:1 '''2 4.编写函数,功能:找出多个数中的最大值与最小值。3 '''4 def findNumValue(list=[]):5for i in range(len(list)-1):6for j in range(len(list)-...
·
Python找出列表中数字的最大值和最小值
思路:
先使用冒泡排序将列表中的数字从小到大依次排序
取出数组首元素和尾元素
运行结果:
源代码:
1 '''
2 4.编写函数,功能:找出多个数中的最大值与最小值。3 '''
4 def findNumValue(list=[]):5 for i in range(len(list)-1):6 for j in range(len(list)-1-i):7 if list[j]>list[j+1]:8 temp=list[j]9 list[j]=list[j+1]10 list[j+1]=temp11 print("最小值:{0}".format(list[0]))12 print("最大值:{0}".format(list[len(list)-1]))
更多推荐
已为社区贡献2条内容
所有评论(0)