def f(N, end):
if end==-1:
N=[1]+N
print (N)
return (N)
if N[end]!=9:
N[end]+=1
return (N)
if N[end]==9:
N[end]=0
end-=1
print (N)
f(N,end)
L=[9,9,9,9,9]
print(f(L, len(L)-1))
You are missing the return clause in the second if statement
if N[end]!=9:
N[end]+=1
return (N)
if N[end]==9:
N[end]=0
end-=1
print (N)
return f(N,end)
By fixing your code like that it should work
你的函数在你的第三个if
语句上没有return
语句(这就是为什么打印None
,默认情况下你的函数返回None
)它只会改变你的列表N
( L
),如果你打印你的列表L
你会看到结果是[0, 0, 0, 0, 0]
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.