输入四门成绩,输出最高分最低分平均数python
时间: 2023-07-01 10:18:42 浏览: 134
好的,可以使用以下代码实现:
```python
scores = []
for i in range(4):
score = float(input("请输入第%d门成绩:"%(i+1)))
scores.append(score)
max_score = max(scores)
min_score = min(scores)
average = sum(scores) / len(scores)
print("最高分为:%.2f" % max_score)
print("最低分为:%.2f" % min_score)
print("平均分为:%.2f" % average)
```
这段代码中,我们首先定义了一个空列表 `scores`,然后使用 `for` 循环和 `input` 函数依次输入四门成绩并将其添加到列表中。接着,我们使用内置函数 `max`、`min` 和 `sum` 计算最高分、最低分和总成绩,并使用 `len` 函数获取成绩数量计算平均分。最后,使用 `print` 函数输出结果。
相关问题
以此输入四门成绩,输出四门成绩的最高分最低分和平均数python
好的,可以使用以下代码实现:
```python
score1 = float(input("请输入第1门成绩:"))
score2 = float(input("请输入第2门成绩:"))
score3 = float(input("请输入第3门成绩:"))
score4 = float(input("请输入第4门成绩:"))
max_score = max(score1, score2, score3, score4)
min_score = min(score1, score2, score3, score4)
average = (score1 + score2 + score3 + score4) / 4
print("最高分为:%.2f" % max_score)
print("最低分为:%.2f" % min_score)
print("平均分为:%.2f" % average)
```
这段代码中,我们使用 `input` 函数依次输入四门成绩,并将其分别赋值给变量 `score1`、`score2`、`score3`、`score4`。接着,我们使用内置函数 `max`、`min` 和 `sum` 计算最高分、最低分和总成绩,并用总成绩除以4计算平均分。最后,使用 `print` 函数输出结果。
使用python输入四门成绩,输出四门成绩的最大值最小值和平均值
好的,以下是使用 Python 计算四门成绩的最大值、最小值和平均值的代码:
```python
# 输入四门成绩
score1 = float(input("请输入第一门成绩:"))
score2 = float(input("请输入第二门成绩:"))
score3 = float(input("请输入第三门成绩:"))
score4 = float(input("请输入第四门成绩:"))
# 计算最大值、最小值和平均值
max_score = max(score1, score2, score3, score4)
min_score = min(score1, score2, score3, score4)
avg_score = (score1 + score2 + score3 + score4) / 4
# 输出结果
print("最大值为:", max_score)
print("最小值为:", min_score)
print("平均值为:", avg_score)
```
你可以将这段代码复制到 Python 环境中运行,然后输入四门成绩,程序就会输出最大值、最小值和平均值。