我写了一个计算两个数字的GCD的代码。 (24,12)的gcd是12.函数compute_gcd
计算GCD并返回在主函数中打印的GCD。但是,当我将其返回到主函数时,输出为none
,当我在compute_gcd
函数本身中打印时,输出为12。使用计算GCD - Python函数返回
我在返回GCD时出错了?
def compute_gcd(a,b):
if(b==0):
return a # Prints 12 if I replace with print a
else:
compute_gcd(b,a%b)
def main():
a=24
b=12
print compute_gcd(a,b) # Prints none
main()
在'else'部分不归路 –
的可能的复制[我希望“真”,但得到“无”(HTTP内://www.stackoverflow.com/questions/15210646/i-expect-true-but-get-none) –