Python-100-Days/Day01-15/Day07/avgscore.py

28 lines
615 B
Python
Raw Normal View History

2018-04-27 00:00:22 +08:00
"""
输入学生考试成绩计算平均分
Version: 0.1
Author: 骆昊
Date: 2018-03-06
"""
def main():
number = int(input('请输入学生人数: '))
names = [None] * number
scores = [None] * number
for index in range(len(names)):
names[index] = input('请输入第%d个学生的名字: ' % (index + 1))
scores[index] = float(input('请输入第%d个学生的成绩: ' % (index + 1)))
total = 0
for index in range(len(names)):
print('%s: %.1f' % (names[index], scores[index]))
total += scores[index]
print('平均成绩是: %.1f' % (total / number))
if __name__ == '__main__':
main()