以下程序有效,但在给出结果时,后跟“无”。如何删除该效果?感谢。
def grades(score):
if score > 1.0:
print("Error, please enter numeric input between 0 and 1.0.")
elif score >= 0.9:
print("The score is: A.")
elif score >= 0.8:
print("The score is: B.")
elif score >= 0.7:
print("The score is: C.")
elif score >= 0.6:
print("The score is: D.")
elif score >= 0:
print("The score is: F.")
else:
print("Error, please enter numeric input between 0 and 1.0.")
try:
score1 = float(input("Enter Score: "))
x = grades(score1)
print(x)
except:
print("Error, please enter numeric input between 0 and 1.0.")
答案 0 :(得分:0)
最后不要print(x)
。 x
是grades
函数的返回值,由于您从不使用return
,因此默认值为None
。所以就这样做
try:
score1 = float(input("Enter Score: "))
grades(score1)
except:
...
答案 1 :(得分:0)
你没有从功能中返回任何东西。而不是使用print,使用return并使用相同的代码。它不会打印。否则你可以删除print(x)。下面应该工作
def grades(score):
if score > 1.0:
print("Error, please enter numeric input between 0 and 1.0.")
elif score >= 0.9:
print("The score is: A.")
elif score >= 0.8:
print("The score is: B.")
elif score >= 0.7:
print("The score is: C.")
elif score >= 0.6:
print("The score is: D.")
elif score >= 0:
print("The score is: F.")
else:
print("Error, please enter numeric input between 0 and 1.0.")
try:
score1 = float(input("Enter Score: "))
x = grades(score1)
#print(x)
except:
print("Error, please enter numeric input between 0 and 1.0.")
答案 2 :(得分:0)
您不会从 properties.setProperty("mail.smtp.host", host);
properties.setProperty("mail.smtp.port", port);
返回任何内容,因此grades()
为x
答案 3 :(得分:0)
成绩是一个不返回任何东西的函数 所以当你写作
x = grades(score1)
x未获得任何值集
因为成绩函数不会返回任何内容
so, print(x) prints None
删除
x = grades(score1)
print(x)
并将其替换为
grades(score1)
你不会得到无
或者如果您想存储成绩的值,然后打印它 将成绩函数更改为
def grades(score):
if score > 1.0:
return "Error, please enter numeric input between 0 and 1.0."
elif score >= 0.9:
return "The score is: A."
elif score >= 0.8:
return "The score is: B."
elif score >= 0.7:
return "The score is: C."
elif score >= 0.6:
return "The score is: D."
elif score >= 0:
return "The score is: F."
else:
return "Error, please enter numeric input between 0 and 1.0."
elif score >= 0:
return "The score is: F."
else:
return "Error, please enter numeric input between 0 and 1.0."