(1)自定义函数minimum3():返回三个数中最小数,第三个参数默认值为100 (2)按位置参数传递,实参分别为-1,0,3 (3)按形参名进行参数传递,z=6,y=4, x=-1 (4)只传入两个参数10,5,最后一个参数采用默认值 测试输入: 预期输出: -1 -1 5
时间: 2024-01-22 07:04:08 浏览: 20
以下是代码实现:
```python
def minimum3(x, y, z=100):
return min(x, y, z)
# 按位置参数传递
print(minimum3(-1, 0, 3)) # 输出:-1
# 按形参名进行参数传递
print(minimum3(z=6, y=4, x=-1)) # 输出:-1
# 只传入两个参数10,5,最后一个参数采用默认值
print(minimum3(10, 5)) # 输出:5
```
解释一下输出结果:
- 在第一个测试中,按位置参数传递,实参分别为-1,0,3,所以函数返回的是-1、0、3三个数中的最小值-1。
- 在第二个测试中,按形参名进行参数传递,z=6,y=4,x=-1,所以函数返回的是-1、4、6三个数中的最小值-1。
- 在第三个测试中,只传入了两个参数10和5,最后一个参数采用默认值100,所以函数返回的是5、10、100三个数中的最小值5。
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![7z](https://img-home.csdnimg.cn/images/20210720083312.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![py](https://img-home.csdnimg.cn/images/20210720083646.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)