0
我寫了此程序得到這個輸出的希望:Python的「無」印刷
True
True
False
False
,我與「無」我的預期輸出之間的印刷得到它:
True
None
True
None
False
None
False
None
我不知道爲什麼這些「無」字符串正在打印,任何幫助將不勝感激!這裏是我的代碼:
# function: check_answer
# input: two numbers (number1 & number2, both integers); an answer (an integer)
# and an operator (+ or -, expressed as a String)
# processing: determines if the supplied expression is correct. for example, if the operator
# is "+", number1 = 1, number2 = 2 and answer = 3 then the expression is correct
# (1 + 2 = 3).
# output: returns True if the expression is correct, False if it is not correct
def check_answer (number1, number2, answer, operator):
if operator == "+":
test = number1 + number2
if test == answer:
print ("True")
else:
print ("False")
if operator == "-":
test2 = number1 - number2
if test2 == answer:
print ("True")
else:
print ("False")
return
answer1 = check_answer(1, 2, 3, "+")
print (answer1)
answer2 = check_answer(1, 2, -1, "-")
print (answer2)
answer3 = check_answer(9, 5, 3, "+")
print (answer3)
answer4 = check_answer(8, 2, 4, "-")
print (answer4)
非常感謝!