#两次递归调用
def num1(a,b):
if b ==1:
return a
else:
return 10 * num1(a,b-1) + a
def sum1(a,b):
if b ==1:
return a
else:
return sum1(a,b-1)+num1(a,b)
print(sum1(2,3))
#while循环计算
def sum2(a,b):
n = a
p = 1
m = a
while p < b:
n = 10*n + a
m += n
p += 1
return m
print(sum2(3,3))
#for循环计算
def sum3(a,b):
n = a
m = a
for i in range(b-1):
n = 10*n + a
m += n
return m
print(sum3(2,3))
#求a+aa+aaa+aaaa+aaaaa和的三种算法
猜你喜欢
转载自blog.csdn.net/weixin_42569562/article/details/81407543
今日推荐
周排行