diff --git a/01.基础语法/03.python认识函数.md b/01.基础语法/03.python认识函数.md index aeacf46..16949ac 100644 --- a/01.基础语法/03.python认识函数.md +++ b/01.基础语法/03.python认识函数.md @@ -264,6 +264,29 @@ def maxx(a,b,c,d): ret = maxx(23,453,12,-13) print(ret) + +# 传入任意多的数字,甚至有重复的,还有非数字(忽略),得到最大的值 + +def my_max(x, y): + m = x if x > y else y + return m + + +def maxx(*nums): + temp_nums = [] + for i in nums: + if type(i) is int: + temp_nums.append(i) + while len(temp_nums) > 1: + a_num = temp_nums.pop() + b_num = temp_nums.pop() + ret = my_max(a_num, b_num) + temp_nums.append(ret) + return temp_nums[0] + + +ret = maxx(123, 3345, 123, 9999, 123, 345, 345, 667, 123, 435, 657, 16, 21, "aabc", ["a", "b"]) +print(f"数值类型中最大的是{ret}") ``` ```python