首先要找到两个数字的"lcm"我做了一个函数lcm(a, b).然后我想找到"hcf",所以我做了一个装饰器decor并hcf(a, b)在其中定义了一个函数.然后我通过输入函数的名称返回此函数,我没有使用括号,但它仍然有效.我不明白为什么这个功能工作,即使我没有使用括号.
def decor(lcm_arg): # just to practice decorators
def hcf(a, b):
if a > b:
a, b = b, a
while True:
if b % a == 0:
print("hcf is", a)
break
else:
a, b = b % a, a
return lcm_arg(a, b)
return hcf # how hcf function is working without using brackets
@decor
def lcm(a, b):
if a > b:
a, b = b, a
for x in range(b, a*b+1, …Run Code Online (Sandbox Code Playgroud)