【发布时间】:2016-12-15 03:44:54
【问题描述】:
谁能帮我解释一下这段代码是如何工作的?我试图了解递归是如何工作的以及如何编写它。新同学,谢谢。
def gcdRecur(a, b):
'''
a, b: positive integers
returns: a positive integer, the greatest common divisor of a & b.
'''
if b == 0:
return a
else:
return gcdRecur(b,a % b)
obj = gcdRecur(9,12)
print (obj)
【问题讨论】:
-
欢迎来到 stackoverflow :) 与其问“谁能向我解释这是如何工作的”,不如阅读欧几里得算法上的维基百科页面,并询问一个更具体的问题你被困在的确切部分。否则很难回答你的问题,因为不清楚你需要什么帮助。 stackoverflow.com/tour 值得一读。
-
欢迎来到 StackOverflow。请阅读并遵循帮助文档中的发布指南。 on topic 和 how to ask 在这里申请。 StackOverflow 不是编码或教程服务。
标签: algorithm recursion iteration