明白用可变函数:
def product(*x):
if x==():
raise TypeError()
else:
y=1
for n in x:
y = y * n
return y
但是我用默认函数为什么run报错呢,单次运行答案也一样的啊
def product(x, y=1, a=1, b=1, c=1):
if x == ():
sum=0
sum = x * y * a * b *c
print(sum)
找到原因了,没有写return
Sign in to make a reply
再来三碗酒
明白用可变函数:
def product(*x):
if x==():
raise TypeError()
else:
y=1
for n in x:
y = y * n
return y
但是我用默认函数为什么run报错呢,单次运行答案也一样的啊
def product(x, y=1, a=1, b=1, c=1):
if x == ():
raise TypeError()
else:
sum=0
sum = x * y * a * b *c
print(sum)