我正在学习Mark Winterbottom为绝对初学者开设的Python课程,模块部分。我做了一个后续任务,我确实遵循了每一步,但它给了我一个马克没有的错误。请帮助。这里是一个完整的代码(第一个模块部分,然后脚本):
"""
Module for exam predictions.
"""
def get_avg(score_histrory):
"""Takes a list of previous grades and returns average."""
return sum(score_history) / len(score_history)
def predict_score(score_history, min_score=0):
"""Takes a list of previous persentage grades and returns the average."""
score_avg = get_avg(score_history)
if score_avg < min_score:
return min_score
return score_avg
"""
Functions for calculating results.
"""
A_THRESHOLD = 70
B_THRESHOLD = 60
C_THRESHOLD = 50
D_THRESHOLD = 40
E_THRESHOLD = 30
def get_grade(score):
"""Accepts a score and returns a letter version."""
if score >= A_THRESHOLD:
return 'A'
elif score >= B_THRESHOLD:
return 'B'
elif score >= C_THRESHOLD:
return 'C'
elif score >= D_THRESHOLD:
return 'D'
elif score >= E_THRESHOLD:
return 'E'
return 'F'
"""
Srcipt for proccessing students grades.
"""
from grades.predict import predict_score
from grades.results import get_grade
score_history = [5, 10, 10, 2]
predicted_score = predict_score(score_history)
predicted_grade = get_grade(predicted_score)
print(f'The students predicted grade is: {predicted_grade}')
NameError: name 'score_history' is not defined
非常感谢。这是我第一次在这里提问。希望您的支持。
我想你的代码"历史"而不是"history":
def get_avg(score_history):
"""Takes a list of previous grades and returns average."""
return sum(score_history) / len(score_history)