我不会啊不会啊
def func(x):
if isinstance(x,list):
sum=0
for a in x:
if isinstance(a,float) or isinstance(a,int):
sum+=a
else:
sum='类型错误,list中有非floa或非int型的元素'
return sum
if isinstance(x,tuple):
sum=0
for a in x:
if isinstance(a,float) or isinstance(a,int):
sum+=a*a
else:
sum='类型错误,tuple中有非floa或非int型的元素'
return sum
else:
sum='类型错误'
return sum
a=[1,2,3,4,5,'a']
b=(1,2,3,4,5,'b')
c={'a':1}
print(func(a))
print(func(b))
print(func(c))