请问用python怎么解呢 xiaoxiaobaozi 发表于 2021-10-19 21:39
人家已经把pseudo code写在那里了。Python code: def gcd(a: int, b :int): ____if b == 0: ________return a ____else: ________c = a%b ________return gcd(b, c) nj_guy 发表于 2021-10-19 22:18
我没有algorithm 知识 xiaoxiaobaozi 发表于 2021-10-19 22:22
too long. one line only: return a if b == 0 else return gcd(b, a%b) gokgs 发表于 2021-10-19 22:37
你这是在问作业么 wfmlover 发表于 2021-10-19 22:40
你自己到pycharm上run一下你那个辣鸡code,看能不能出数。连个function header都没有,还一行呢。 nj_guy 发表于 2021-10-19 22:45
用循环或者recursion都可以
再细的要自己想了啊楼主
用recursive,if... else...。题目已经给的很明显了。
def gcd(a: int, b :int): ____if b == 0: ________return a ____else: ________c = a%b ________return gcd(b, c)
没有算法知识就去补吧。
too long. one line only:
return a if b == 0 else return gcd(b, a%b)
python is the stupid programming language I can imagine.
you need be more familiar with programming language first, they told you the algorithm already in this case.
你自己到pycharm上run一下你那个辣鸡code,看能不能出数。连个function header都没有,还一行呢。
不是作业。是工作上临时让我参加一个班。但是有入学考试。就这三个题。我也没有编程经验。所以只能上网求高人指点一下
他那个写的只是一点不对,多了个return
def gcd(a, b): __return a if b == 0 else gcd(b, a%b)
这个差不多