如何使用gradePercent
转换最终消息函数以获得65.9和letterGrade
来获得C并使其显示实际消息作为示例:
"如果事情继续发展,你应该在课程中获得65.9%,这是C。">
print("If things keep going the way they are, you should get a " earnedPercent "in the course, which is a " + earnedGrade")
我还想知道一种方法,如果你输入不同的输入,如何自动将最终百分比从100%-0%和字母从a-F更改。
您可以将其添加到末尾,以获得基于百分比的正确消息格式:
gradePercent=76.5
score=int(gradePercent)
if score > 90:
letterGrade= "A"
elif 80 <= score < 90:
letterGrade= "B"
elif 70 <= score < 80:
letterGrade= "B"
elif 60 <= score < 70:
letterGrade= "C"
elif 50 <= score < 60:
letterGrade= "D"
else:
letterGrade= "F"
#python2
message='If things keep going the way they are, you should get a {:.00f}% in the course, which is a {:s}.'.format(gradePercent, letterGrade)
#python3
#message=f'If things keep going the way they are, you should get a {gradePercent:.00f}% in the course, which is a {letterGrade}.'
print(message)