【发布时间】:2021-12-10 00:45:27
【问题描述】:
我试图在这个递归函数中返回count,但它总是返回无。当我做print(count) 而不是return count 时,它给了我正确的结果。谁能告诉我我做错了什么?提前非常感谢你:)
count = 0
def count_lowercase(s, low, high):
global count
if low > high:
return count
else:
if s[low] == s[low].lower():
count += 1
count_lowercase(s, low + 1, high)
【问题讨论】:
-
你需要
return count_lowercase(s, low+1, high) -
最后一行需要返回count_lowercase