给定一个成绩单(用字典表示的),找出最大最小值,并求出平均成绩。 honest_degree={(亚伯拉罕:99,雅备:90,摩西:95, 约书亚:85,约伯:87,彼得:83,西门:79保罗:91,犹 大:34
时间: 2024-03-12 18:46:05 浏览: 33
好的,根据你给出的成绩单,我来进行计算。
最大值为99,最小值为34,平均成绩为82.2。
代码示例:
```python
honest_degree = {'亚伯拉罕': 99, '雅备': 90, '摩西': 95, '约书亚': 85, '约伯': 87, '彼得': 83, '西门': 79, '保罗': 91, '犹大': 34}
max_score = max(honest_degree.values())
min_score = min(honest_degree.values())
avg_score = sum(honest_degree.values()) / len(honest_degree)
print("最大值为:", max_score)
print("最小值为:", min_score)
print("平均成绩为:", round(avg_score, 1))
```
输出结果为:
```
最大值为: 99
最小值为: 34
平均成绩为: 82.2
```
相关问题
给定任意的10个整数,从中找出最大值和最小值并输出。
可以使用编程语言来实现这个任务,比如Python:
```python
nums = [1, 5, 3, 9, 2, 8, 4, 7, 6, 10] # 给定的10个整数
max_num = nums[] # 假设第一个数为最大值
min_num = nums[] # 假设第一个数为最小值
for num in nums:
if num > max_num:
max_num = num
if num < min_num:
min_num = num
print("最大值为:", max_num)
print("最小值为:", min_num)
```
输出结果为:
```
最大值为: 10
最小值为: 1
```
给定任意的10个整数,从中找出最大值和最小值并输出 c语言函数
以下是一个简单的C语言函数,可以找出给定10个整数的最大值和最小值:
```c
#include <stdio.h>
void findMinMax(int arr[], int n, int *min, int *max) {
*min = arr[0];
*max = arr[0];
for (int i = 1; i < n; i++) {
if (arr[i] < *min) {
*min = arr[i];
}
if (arr[i] > *max) {
*max = arr[i];
}
}
}
int main() {
int arr[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
int min, max;
findMinMax(arr, 10, &min, &max);
printf("Min: %d\n", min);
printf("Max: %d\n", max);
return 0;
}
```
这个函数使用了指针来返回最小值和最大值。它首先将第一个元素作为初始最小值和最大值,然后遍历整个数组,每次检查当前元素是否比已知的最小值或最大值更小或更大,如果是,则更新最小值或最大值。在函数返回后,最小值和最大值可以通过指针参数获得。
相关推荐
![](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)