《Python》求帮助
请编写一个函数student_grade,该函数可以接收一个学生的姓名及任意多的课程成绩,函数的任务为:
判断该学生的课程个数是否小于3,如果小于3门,那么提示该学生未完成课时要求。
如果该学生已达到学分要求,计算该学生学科成绩的平均值,并判断该学生的平均值是否超过60,如果未超过60分,则提示该学生未完成平均分数要求。
如果条件都满足,则提示该学生已达标。
• 调用该函数一次。
def student_grade(name, *grades):
if len(grades) < 3:
print(name + "未完成课时要求。")
else:
average = sum(grades) / len(grades)
if average >= 60:
print(name + "已达标。")
else:
print(name + "未完成平均分数要求。")
# 调用函数测试
student_grade('小明', 80, 70, 90
glossary = {
'string': 'A series of characters.',
'comment': 'A note in a program that the Python interpreter ignores.',
'list': 'A collection of items in a particular order.',
'loop': 'Work through a collection of items, one at a time.',
'dictionary': "A collection of key-value pairs.",
}
word = 'string'
print("\n" + word.title() + ": " + glossary[word])
word = 'comment'
print("\n" + word.title() + ": " + glossary[word])
word = 'list'
print("\n" + word.title() + ": " + glossary[word])
word = 'loop'
print("\n" + word.title() + ": " + glossary[word])
word = 'dictionary'
print("\n" + word.title() + ": " + glossary[word])