python定义函数get_max,返回用户输入10个数中的最大值
时间: 2024-05-12 11:20:29 浏览: 14
以下是Python代码实现:
```python
def get_max():
nums = []
for i in range(10):
num = float(input("请输入第{}个数:".format(i+1)))
nums.append(num)
return max(nums)
print("最大值为:", get_max())
```
首先定义函数`get_max()`,函数内部通过`for`循环获取用户输入的10个数,将这些数存储在列表`nums`中。然后使用`max()`函数求出列表中的最大值,将其作为函数的返回值。
最后在主函数中调用`get_max()`函数,并输出最大值。
相关问题
python定义函数get_max,返回用户输入10个数中的最大值,要求:不能使用内置函数sort进行排序,要求自己比较每个数。
```python
def get_max():
nums = []
for i in range(10):
num = int(input('请输入第{}个数:'.format(i+1)))
nums.append(num)
max_num = nums[0]
for num in nums:
if num > max_num:
max_num = num
return max_num
```
定义函数get_max,返回用户输入10个数中的最大值,要求:不能使用内置函数sort进行排序,要求自己比较每个数。
```python
def get_max():
nums = []
for i in range(10):
num = int(input("请输入第{}个数:".format(i+1)))
nums.append(num)
max_num = nums[0]
for num in nums:
if num > max_num:
max_num = num
return max_num
```
相关推荐
![py](https://img-home.csdnimg.cn/images/20210720083646.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)