def func(L):
s = 0
C = 0
if isinstance(L,list) :
s = sum(L)
return s
elif isinstance(L,tuple):
for F in L:
C = F*C
return C
else :
print("Error")
print(func([1,2,3]))
print(func((1,2,3)))
IndentationError: unindent does not match any outer indentation level
def func(L):
s = 0
c = 1
if isinstance(L, list):
s = sum(L)
return s
elif isinstance(L, tuple):
for F in L:
c = c * F
return c
else:
print("Error")
print(func([1, 2, 3]))
print(func((1, 2, 3)))
以上正确代码,你的缩进错误在于第二个判断c = c * F和return c这里,第二个错误是算法问题,元组的元素乘绩c的初始值等于0,你乘法过关应该知道结果是什么。
翻译
搜索
复制
翻译
搜索
复制