求一批数中最大值,最小值的差和积程序编程
时间: 2023-09-24 21:02:27 浏览: 33
C语言程序设计-求一批数中最大值和最小值的积;.c
5星 · 资源好评率100%
以下是 Python 代码实现:
```python
nums = [3, 7, 9, 2, 8, 6] # 示例数字列表
# 求最大值
max_num = max(nums)
print("最大值为:", max_num)
# 求最小值
min_num = min(nums)
print("最小值为:", min_num)
# 求差值
diff = max_num - min_num
print("差值为:", diff)
# 求积
product = 1
for num in nums:
product *= num
print("积为:", product)
```
输出结果:
```
最大值为: 9
最小值为: 2
差值为: 7
积为: 18144
```
阅读全文