编程小白求助

x
xiaoxiaobaozi
楼主 (北美华人网)
谢谢🙏
x
xiaoxiaobaozi
请问用python怎么解呢
j
julie2020
请问用python怎么解呢
xiaoxiaobaozi 发表于 2021-10-19 21:39

用循环或者recursion都可以
再细的要自己想了啊楼主
g
gokgs
This is super easy. Recursive. Only 3 lines of code?
星月花草
回复 1楼xiaoxiaobaozi的帖子
用recursive,if... else...。题目已经给的很明显了。
n
nj_guy
人家已经把pseudo code写在那里了。Python code:
def gcd(a: int, b :int): ____if b == 0: ________return a ____else: ________c = a%b ________return gcd(b, c)
x
xiaoxiaobaozi
我没有algorithm 知识
x
xiaoxiaobaozi




x
xiaoxiaobaozi
🙏😂☝️
星月花草
回复 9楼xiaoxiaobaozi的帖子
没有算法知识就去补吧。
g
gokgs
人家已经把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

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.
g
gokgs
我没有algorithm 知识
xiaoxiaobaozi 发表于 2021-10-19 22:22

you need be more familiar with programming language first, they told you the algorithm already in this case.
w
wfmlover
你这是在问作业么
j
judym
lz如果学编程遇到问题,大家自然愿意帮忙,不过你这明显是让网友帮你做题吧,一共三道题,全贴上来了
n
nj_guy
too long. one line only:
return a if b == 0 else return gcd(b, a%b)
gokgs 发表于 2021-10-19 22:37

你自己到pycharm上run一下你那个辣鸡code,看能不能出数。连个function header都没有,还一行呢。
x
xiaoxiaobaozi
你这是在问作业么
wfmlover 发表于 2021-10-19 22:40

不是作业。是工作上临时让我参加一个班。但是有入学考试。就这三个题。我也没有编程经验。所以只能上网求高人指点一下
w
wendywu00
就一递归函数。
h
happyannie
def gcd(a, b): ___return a if b == 0 else gcd(b, a%b)
e
elevenoclock
这不需要算法知识,就是最基本的coding,找个最最简单的tutorial看一下就知道了
s
seven11
你自己到pycharm上run一下你那个辣鸡code,看能不能出数。连个function header都没有,还一行呢。
nj_guy 发表于 2021-10-19 22:45

他那个写的只是一点不对,多了个return
def gcd(a, b): __return a if b == 0 else gcd(b, a%b)
这个差不多
x
xiaoxiaobaozi
谢谢大家的帮助和建议 我会接下去好好学习的