python递归函数练习

假设有m个人坐在一起,第1个人比第2个人大n岁,第2个人比第3个人大n岁,第3个比第4个人大n岁,以此类推,直到问第m个人,他说他10岁。请编写程序,输入正整数m,n,计算并输出第1个人的年龄。
第一行为输入,第二行为输出。
【运行效果1】
8 3
31
【运行效果2】
5 2
18

https://blog.csdn.net/qq_38149225/article/details/109269833

改写下

def Age(m, n):
    if n==1:
        return 10
    else:
        return Age(m-1, n)+n
m, n = map(int, input().split())
a=Age(m, n)
printf(a)

def cacl_age(m, n, cur_person_age):
    if m == 2:
        return cur_person_age + n
    else:

        return cacl_age(m-1, n, cur_person_age + n)


first_person = cacl_age(5, 2, 10)
print("The age of first person is {}".format(first_person))

first_person = cacl_age(8, 3, 10)
print("The age of first person is {}".format(first_person))