Udacity Python替换列表中的数字

时间:2013-07-26 03:41:03

标签: python

我不确定为什么我的解决方案无效。我通过'间谍'然后将一个添加到列表的第3个元素。

提前致谢!

# Define a procedure, replace_spy,
# that takes as its input a list of
# three numbers, and modifies the
# value of the third element in the
# input list to be one more than its
# previous value.

spy = [0,0,7]

def replace_spy(a):
    replace_spy[2] +1


# In the test below, the first line calls your 
# procedure which will change spy, and the 
# second checks you have changed it.
# Uncomment the top two lines below.

replace_spy(spy)
print spy
#>>> [0,0,8]

1 个答案:

答案 0 :(得分:0)

在该功能中,您应该在a上执行。

def replace_spy(a):
    a[2] += 1