我有点想知道该怎么做,但我无法弄清楚。该程序需要能够获取学生姓名和三个考试成绩,然后得到三个分数的平均分(百分比)。之后,您需要将分数(百分比)转换为成绩。
编辑: 我将如何删除成绩中间的空格和“%”?
- 请按“Enter”开始
- 输入您的姓名:乔丹·辛普森
- 初试成绩:67%
- 第二次考试成绩:78%
- 第三次考试成绩:89%
- 最终字母等级:C+
- 乔丹辛普森测试分数是:78.0 %
- 是否要重新启动程序?
分级量表:
input ('Please press "Enter" to begin')
while True:
import math
studentName = str(input('Enter your Name: '))
firstScore = int(float(input('First test score: ').replace('%', '')))
secondScore = int(float(input('Second test score: ').replace('%', '')))
thirdScore = int(float(input('Third test score: ').replace('%', '')))
scoreAvg = (firstScore + secondScore + thirdScore) / 3
def grade():
if scoreAvg >= 93 and <= 100:
return 'A'
if scoreAvg <= 92.9 and >= 89:
return 'A-'
if scoreAvg <= 88.9 and >= 87:
return 'B+'
if scoreAvg <= 86.9 and >= 83:
return 'B'
if scoreAvg <= 82.9 and >= 79:
return 'B-'
if scoreAvg <= 78.9 and >= 77:
return 'C+'
if scoreAvg <= 76.9 and >= 73:
return 'C'
if scoreAvg <= 72.9 and >= 69:
return 'C-'
if scoreAvg <= 68.9 and >= 67:
return 'D+'
if scoreAvg <= 66.9 and >= 60:
return 'D'
return 'F'
print(grade(scoreAvg))
print(studentName, "test score is: ",scoreAvg,'%')
endProgram = input ('Do you want to restart the program?')
if endProgram in ('no', 'No', 'NO', 'false', 'False', 'FALSE'):
break