我正在设计一个简单的代码,从总共5个给定的测试中确定一个学生的成绩为p(>;65%)或NP。这是我迄今为止为它设计的代码,基于我的教授希望它的方式,我希望总正确的结果显示为一个百分比,但我一直有困难找到正确的方法来编码这个。你知道吗
# Initialize Variables
studentName = "no name"
test1 = 0
test2 = 0
test3 = 0
test4 = 0
test5 = 0
totalScore = 0
finalGrade = 0
gradeMessage = None
# Print report title
print("\n Isabelle S - Programming Problem Two")
# Get user input data
studentName = input("Enter name of student ")
test1 = int(input("Enter test score 1: "))
test2 = int(input("Enter test score 2: "))
test3 = int(input("Enter test score 3: "))
test4 = int(input("Enter test score 4: "))
test5 = int(input("Enter test score 5: "))
# Compute values
totalScore = test1 +test2 +test3 + test4 + test5
finalGrade = totalScore / 100 * 100.0
if finalGrade >65:
gradeMessage = "P"
else:
gradeMessage = "NP"
# Print detail lines
print("\n Name of student: " , studentName )
print("Total Correct: " , totalScore )
print("Final Grade: " , gradeMessage )
要计算百分比,需要除以最大总分,然后乘以100得到百分比。你知道吗
伊莎贝尔,你需要知道每个测试中的最大可能点是什么(
test1
、test2
、test3
、test4
和test5
)。假设每个测试中的最大可能点是100,可以稍微更改代码。您可以使用finalGrade = totalScore / 5
,而不是finalGrade = totalScore / 100 * 100.0
。你知道吗下面是完整的代码(带有前面提到的更改)。=)
相关问题 更多 >
编程相关推荐