09-09-周二_11-09-08

This commit is contained in:
2025-09-09 11:09:08 +08:00
parent 943fe31213
commit ef17c66fac

View File

@@ -264,6 +264,29 @@ def maxx(a,b,c,d):
ret = maxx(23,453,12,-13) ret = maxx(23,453,12,-13)
print(ret) 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 ```python