英语学习笔记2019-11-22
Review
the composition of a computer system
1. Hardware
- Control Unit -- instruction <-- program
- ALU (Arithmetic & Logic Unit) -- operation (operator + operand(data))
Control Unit + ALU = CPU (Central Processing Unit)
- Storage Unit (Primary Memory, Secondary Storage)
- Input Devices -- keyboard, mouse, microphone, webcam, scanner...
- Output Devices -- display, printer, speaker, plotter....
2. Software
- System Software -- OS (Operating System), Language Processor, DBMS...
- Application Software


Today we're going to learn something about Algorithms and Data Structures.









Score Calculating Problem in Singing Competition
For each singer, 10 judges give ten scores.
Let's consider how to calculate the final score for each singer.
The highest and lowest scores will be eliminated, and the average of the remaining eight scores will be the final score.
1. input ten scores and save them in a list

Run the program and the result goes like this:

2. calculate the highest and lowest scores

Run the program and let's take a look at the result:

3. calculate the final score

"""
计算歌手最终得分
10个评委,10个分数
去掉一个最高分,去掉一个最低分
然后求出平均分作为歌手最终得分
"""
# 输入10个分数存放到列表里
scores = []
for i in range(10):
score = float(input('scores[%d] = ' %i))
scores.append(score)
print('scores =', scores)
# 求出最高分与最低分
max_score = scores[0]
for i in range(1, 10):
if max_score < scores[i]:
max_score = scores[i]
print('max_score = {}'.format(max_score))
min_score = scores[0]
for i in range(1, 10):
if min_score > scores[i]:
min_score = scores[i]
print('min_score = {}'.format(min_score))
# 计算歌手最终得分
sum_score = 0
for score in scores:
sum_score += score
final_score = (sum_score - max_score - min_score) / (len(scores) - 2)
print('final_score = {:.2f}'.format(final_score))
Run the program and the result goes like this:

Of course, this program can be optimized.

"""
计算歌手最终得分
10个评委,10个分数
去掉一个最高分,去掉一个最低分
然后求出平均分作为歌手最终得分
"""
# 输入10个分数存放到列表里
scores = []
for i in range(10):
score = float(input('scores[%d] = ' %i))
scores.append(score)
print('scores =', scores)
# 求出最高分与最低分
max_score = max(scores)
print('max_score = {}'.format(max_score))
min_score = min(scores)
print('min_score = {}'.format(min_score))
# 计算歌手最终得分
sum_score = 0
for score in scores:
sum_score += score
final_score = (sum_score - max_score - min_score) / (len(scores) - 2)
print('final_score = {:.2f}'.format(final_score))
The result is the same:

Actually, we can modify the program like this:

"""
计算歌手最终得分
10个评委,10个分数
去掉一个最高分,去掉一个最低分
然后求出平均分作为歌手最终得分
"""
# 输入10个分数存放到列表里
scores = []
for i in range(10):
score = float(input('scores[%d] = ' %i))
scores.append(score)
print('scores =', scores)
# 成绩排序
scores = sorted(scores)
# 求出最高分与最低分
print('max_score = {}'.format(scores[len(scores) - 1]))
print('min_score = {}'.format(scores[0]))
# 去掉最高分与最低分
scores.pop(len(scores) - 1)
scores.pop(0)
# 计算歌手最终得分
sum_score = 0
for score in scores:
sum_score += score
final_score = sum_score / len(scores)
print('final_score = {:.2f}'.format(final_score))
Let's take a look at the result:

本文深入探讨了计算机系统的组成,包括硬件(如控制单元、算术逻辑单元、存储单元等)和软件(如操作系统、应用软件)。此外,还详细解析了一个评分计算问题,通过去除最高和最低分来计算平均得分,展示了算法实现的多种方法。
813

被折叠的 条评论
为什么被折叠?



