如何格式化期末信息以获得期末成绩

  • 本文关键字:信息 格式化 python
  • 更新时间 :
  • 英文 :


如何使用gradePercent转换最终消息函数以获得65.9letterGrade来获得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)

最新更新