From ef17c66facd51ba266eaf76f6b537a77ac03c51f Mon Sep 17 00:00:00 2001 From: Aaron Date: Tue, 9 Sep 2025 11:09:08 +0800 Subject: [PATCH] =?UTF-8?q?09-09-=E5=91=A8=E4=BA=8C=5F11-09-08?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 01.基础语法/03.python认识函数.md | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) 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