Python循环结构的深入探究与应用
一、测试成绩平均值计算程序
在Python编程中,我们常常需要处理各种数据,计算学生的测试成绩平均值就是一个常见的需求。下面是一个用于计算学生测试成绩平均值的程序:
# This program averages test scores. It asks the user for the
# number of students and the number of test scores per student.
# Get the number of students.
num_students = int(input('How many students do you have? '))
# Get the number of test scores per student.
num_test_scores = int(input('How many test scores per student? '))
# Determine each student's average test score.
for student in range(num_students):
# Initialize an accumulator for the test scores.
total = 0.0
# Display the student number.
print(f'Student number {student + 1}')
print('-----------------')
# Get the student's test scores
超级会员免费看
订阅专栏 解锁全文
878

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



