这里是一个问题:“使用程序功能为5个学生获得姓名,姓氏和4个分数,并最终按平均水平打印出学生的姓名。”
我编写了函数,所以我可以获得每个学生的平均值。但我不知道该如何对学生的姓名进行排序。
_firstname = []
_familiname = []
_scores = []
def student1():
input('Please enter the firstname:')
input('Please enter the familiname:')
for i in range(0, 4):
scores = int(input('Please enter the scores:'))
_scores.append(scores)
b = sum(_scores)
avg1 = b/4
print('avg is',avg1)
def student2():
input('Please enter the firstname:')
input('Please enter the familiname:')
for i in range(0, 4):
scores = int(input('Please enter the scores:'))
_scores.append(scores)
b = sum(_scores)
avg2 = b/4
print('avg is',avg2)
def student3():
input('Please enter the firstname:')
input('Please enter the familiname:')
for i in range(0, 4):
scores = int(input('Please enter the scores:'))
_scores.append(scores)
b = sum(_scores)
avg3 = b/4
print('avg is',avg3)
def student4():
input('Please enter the firstname:')
input('Please enter the familiname:')
for i in range(0, 4):
scores = int(input('Please enter the scores:'))
_scores.append(scores)
b = sum(_scores)
avg4 = b/4
print('avg is',avg4)
def student5():
input('Please enter the firstname:')
input('Please enter the familiname:')
for i in range(0, 4):
scores = int(input('Please enter the scores:'))
_scores.append(scores)
b = sum(_scores)
avg5 = b/4
print('avg is',avg5)
student1()
student2()
student3()
student4()
student5()
这显然是家庭作业,但这是一个起点:
scores = {90:'best', 80:'good', 60:'ehh'}
ordered_scores = sorted(scores.keys())
print('ordered_scores', ordered_scores)
for score in ordered_scores:
print('score', score, 'student', scores[score])
给你
ordered_scores [60, 80, 90]
score 60 student ehh
score 80 student good
score 90 student best
查看是否可以更改排序顺序。祝你好运!