班级成绩表 - PYTHON
我真的不知道从哪里开始。我意识到这是基本的,但如果有人能指导我完成这个,将不胜感激。
我们想要一个程序,让我们可以打印班级学生的“成绩单”。程序应该循环,询问姓名、期中成绩和期末成绩。然后它应该回显输入,并打印输入的信息以及学生的平均值。要退出循环,用户输入小写的“done”。该程序将打印班级平均值,然后终止。
首先将描述的一部分翻译成 Python。
while True:
ask for a name, midterm score, and final score
echo the input
print the information entered, plus the student's average
to exit the loop, the user enters "done" in lower case
print the class average and terminate
然后:
while True:
name = input('Name')
if name == 'done':
break
midterm = input('Midterm score')
final = input('Final score')
average = the student's average
print('Name', name,
'Midterm score', midterm, 'Final score', final, 'Average', average)
class_average = ???
print('Class average', class_average)
计算学生的平均值很容易——您必须将midterm
和转换final
为数字,然后平均这些数字。
计算班级平均值比较棘手。但是,如果您可以将每个分数附加到某种集合中,以便以后进行总结——或者在不需要整个集合的情况下找出需要跟踪的较小的数字集合——这并不难。