问题描述
另一个问题是关于阶数的问题。使用功能
def f(n):
如果n == 0:
r = 1
else:
r = n * f(n-1)
返回r
print('答案是: ',r)
f(0)
这里有什么问题?
错误告诉我:
-------------------------- -------------------------------------------------
NameError Traceback(最近一次调用最后一次)
< ipython-input-68-cc9d7ecb020e>在< module>()
6 r = n * f(n-1)
7返回r
----> ; 8打印('Ans。是:',r)
9 f(0)
NameError:名称'r'未定义
我的尝试:
另一个是关于阶数的问题。使用函数
def f(n):
如果n == 0:
r = 1
else:
r = n * f(n-1 )
返回r
打印('Ans。是:',r)
f(0)
这里有什么问题?
错误告诉我:
-------------------------------- -------------------------------------------
NameError Traceback(最近的呼叫最后一次)
< ipython-input-68-cc9d7ecb020e> in< module>()
6 r = n * f(n-1)
7 return r
----> 8打印('Ans。是:',r)
9 f(0)
NameError:名称'r'未定义
Another is that problem on factorial of a no. using function
def f(n):
if n==0:
r=1
else:
r=n*f(n-1)
return r
print('Ans. is:',r)
f(0)
what is problem here?
Error is showing me that:
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
<ipython-input-68-cc9d7ecb020e> in <module>()
6 r=n*f(n-1)
7 return r
----> 8 print('Ans. is:',r)
9 f(0)
NameError: name 'r' is not defined
What I have tried:
Another is that problem on factorial of a no. using function def f(n): if n==0: r=1 else: r=n*f(n-1) return r print('Ans. is:',r) f(0) what is problem here? Error is showing me that: --------------------------------------------------------------------------- NameError Traceback (most recent call last) <ipython-input-68-cc9d7ecb020e> in <module>() 6 r=n*f(n-1) 7 return r ----> 8 print('Ans. is:',r) 9 f(0) NameError: name 'r' is not defined
这篇关于使用Python中的函数的一个数的因子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!