【发布时间】:2016-07-22 18:23:27
【问题描述】:
请检查我下面的代码并进行必要的更正。它给了我一条错误消息。
作业如下所示。
创建一个函数
manipulate_data执行以下操作
接受
string作为第一个参数,指定要使用的数据结构list、set或dictionary根据指定的数据结构接受要操作的数据作为第二个参数,例如
[1, 4, 9, 16, 25]用于list数据结构基于第一个参数
- 返回列表的反向或
- 将项目
"ANDELA"、"TIA"和"AFRICA"添加到集合并返回结果集合- 返回字典的键。
我的解决方案代码如下:
def manipulate_data(argument1, argument2):
if argument1 == "list":
argument2.reverse()
return argument2
if argument1 == "set":
argument2.add("ANDELA")
argument2.add("TIA")
argument2.add("AFRICA")
return argument2
if argument1 == "dictionary":
argument2.keys()
return argument2
我不知道我是否说得通。收到的错误信息是:
Total Specs: 3 Total Failures: 2
test_manipulate_dictionary
Failure in line 23, in test_manipulate_dictionary self.assertEqual(result, ["grapes", "mangoes", "apples", "oranges"], msg = "Dictionary not manipulated correctly") AssertionError: Dictionary not manipulated correctly
和
test_manipulate_set
Failure in line 19, in test_manipulate_set self.assertEqual(result, {"a", "b", "c", "d", "e", "ANDELA", "TIA", "AFRICA"}, msg = "Set not manipulated correctly") AssertionError: Set not manipulated correctly
【问题讨论】:
-
可能重复of this question.
标签: python list dictionary set