?為什么不對(duì)
def?my_sumA(a): ????if?a+1<=100: ????????sum=a+my_sumA(a+1) ????else: ????????sum=0 ????return?sum print(my_sumA(1)) def?my_sumB(n): ????sum?=?0 ????if?n?==?1: ????????sum?=?n ????else: ????????sum?=?n?+?my_sumB(n?-?1) ????return?sum print(my_sumB(100))
2024-09-15
第一個(gè)函數(shù),當(dāng)a=100時(shí),由于a+1大于100,使得其直接返回而不是100+my_sumA(101),你應(yīng)該把+1去掉或者把100改為101