cardsInHand
def count_to_by(n, a):
if n <= 0:
return n
count_to_by(n - a, a)
print(str(n) + ", ", end="")
count_to_by(30, 4)
input()
非常坚持这个问题。解决方案需要递归,谢谢!
答案 0 :(得分:2)
我会drawableLeft
返回count_to_by
,因此它可以更“通用”。
然后,我们可以使用list
打印值:
', '.join
要回答练习的具体用例,您可以执行与上述操作类似的操作:
def count_to_by(n, a):
return [] if n <= 0 else [n] + count_to_by(n - a, a)
print(', '.join(map(str, reversed(count_to_by(30, 4)))))
# 2, 6, 10, 14, 18, 22, 26, 30