标签:问题 == 个人 胜利 blog integer count 间接 简单
def sum_digits(n): """Return the sum of the digits of positive integer n.""" if n < 10: return n else: all_but_last, last = n // 10, n % 10 return sum_digits(all_but_last) + last
def is_even(n): if n == 0: reutrn True else: return is_odd(n-1) def is_odd(n): if n == 0: return False else: return is_even(n-1) result = is_even(4)
def play_Alice(n): if n == 0: print("Tom wins!") else: play_Tom(n-1) def play_Tom(n): if n == 0: print("Alice wins!") elif(n%2 == 0): play_Alice(n-2) else: play_Alice(n-1)
def Fibo(n): if n == 1: return 0 if n == 2: return 1 if n > 2: return Fibo(n-2) + Fibo(n-1)
def count_partitions(n, m): """Count the ways to partition n using parts up to m.""" if n == 0: return 1 elif n < 0: return 0 elif m == 0: return 0 else: return count_partitions(n-m, m) + count_partitions(n, m-1)
标签:问题 == 个人 胜利 blog integer count 间接 简单
原文地址:http://www.cnblogs.com/EliEyes/p/7060570.html