其他分享
首页 > 其他分享> > 7-2 sdut-列表元素个数的加权和(1)

7-2 sdut-列表元素个数的加权和(1)

作者:互联网

递归

def sum(n,deep):
    sums = 0
    # print(deep)
    for i in n:
        if isinstance(i, list):
            sums += sum(i,deep+1)
        if isinstance(i, int):
            sums +=  deep
    return sums

a = eval(input())
j = 0
print(sum(a,1))

标签:return,个数,sum,sums,deep,列表,sdut,print,isinstance
来源: https://www.cnblogs.com/kingwz/p/16328102.html