20、Python循环结构的深入探究与应用

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
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符  | 博主筛选后可见
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值