2
使用python对学生成绩进行评分。试图从简化,打印文本而不是布尔值,Python
A = ((float(scptratio)) >= (0.9) and (float(scptratio) <= 1))
B = ((float(scptratio)) >= (0.8) and (float(scptratio) <= (0.89)))
if A == True:
print (studentname, (" has scored an A on the test."))
elif B == True:
print (studentname, (" has scored an B on the test."))
elif C == True:
print (studentname, (" has scored an C on the test."))
等简化的东西沿着
A = (((float(scptratio)) >= (0.9) and (float(scptratio) <= 1)), "A")
B = (((float(scptratio)) >= (0.8) and (float(scptratio) <= (0.89))), "B")
Pass = [A, B, C, D]
if Pass:
print (studentname, "passed the test with a coefficient of", scptratio, ("scoring a grade of {}".format(Pass)))
elif F:
print (studentname, "has failed the test.")
else:
print ("Error! Negative value entered.")
行我怎样才能得到它打印的实际字母比分反超布尔值吗?
你真的不应该用大写字母命名你的变量,因为它们可能会与类名冲突。 – Soviut
您可以通过在脚本开始处将'scpratio'转换为float **一次**来大幅提高可读性。 –
谢谢,虽然它通过,但真的很快乐。 – NWC42