如何使用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的方法。
答案 0 :(得分:0)
您可以将其添加到末尾以根据百分比获得正确的消息格式:
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)