本文介绍了有人请看看我的Python语法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有人可以向我解释我的代码中缺少什么?我一直在看互联网上的解决方案,我发现一个模板,我认为是正确的,但仍然给我错误。任何人知道我在做错什么?
def manipulate_data(kind,data):
if kind ==列表:
[1,4,9,16,25]中的数据:
return data.reverse()
elif kind ==set:
data.add(TIA)
data.add(ANDELA)
data.add )
data.add(AFRICA)
返回数据
elif kind ==dictionary:
用于{nissan中的数据:23, audi:15,mercedes:3,volvo:45}:
return data.key()
解决方案
根据问题,这个函数只需要2个参数:
$ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $如果data_type = ='set':
return set.union(data,[ANDELA,TIA,AFRICA])
如果data_type =='dict':
return [ key,item.items()]
Can someone please explain to me what is missing in my code? I have been looking at solutions on the internet and I found a template that I thought would be correct but its still giving me errors. Anyone know what I am doing wrong?
def manipulate_data(kind, data):
if kind == "list":
for data in [1, 4, 9, 16, 25]:
return data.reverse()
elif kind == "set":
for data in {"f", "g", "h", "i", "j"}:
data.add("ANDELA")
data.add("TIA")
data.add("AFRICA")
return data
elif kind == "dictionary":
for data in {"nissan": 23, "audi": 15, "mercedes": 3, "volvo": 45}:
return data.key()
解决方案
This one works according to the question the function only takes in 2 parameters:
def manipulate_data(data_type=None, data=None):
if data_type is 'list':
return data[-1::-1]
if data_type == 'set':
return set.union(data, ["ANDELA", "TIA", "AFRICA"])
if data_type == 'dict':
return [key for key, item in data.items()]
这篇关于有人请看看我的Python语法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!