不确定传参的个数n=(1,2,...) 返回n*n的和

发布时间 2023-07-05 16:08:07作者: 胖豆芽
# 函数 不确定的参数情况下 输出 n*n的和
def calc(numbers):
    total=0
    for n in numbers:
        print(f'n:{n}')
        total=total+n*n
        print(f'total:{total}')
    return total
#调用函数
result=calc((1,2))
print(f'result:{result}')


'''
this x is in the funcx:--> 9
--------------
this x is in the funcx:--> 9
'''
# 函数 不确定的参数情况下 输出 n*n的和
def calc(*numbers):
    total=0
    for n in numbers:
        print(f'n:{n}')
        total=total+n*n
        print(f'total:{total}')
    return total
#调用函数
result=calc(1,2,3)# 不需要强调以元祖形式传入参数
print(f'result:{result}')