我不明白move方法发生了什么。 我正在从Udacity.com学习AI课程。 视频位置为: http : //www.udacity.com/view#Course/cs373/CourseRev/apr2012/Unit/512001/Nugget/480015
下面是我没有得到的代码,它没有按照视频中显示的那样工作。根据Udacity,我应该得到的答案是[0,0,1,0,0] 这是我得到的[]
p=[0, 1, 0, 0, 0] def move(p, U): q = [] for i in range(len(p)): q.append(p[(i-U) % len(p)]) return q print move(p, 1)I don't understand what is going on in the move method. I am taking the AI course from Udacity.com. The video location is: http://www.udacity.com/view#Course/cs373/CourseRev/apr2012/Unit/512001/Nugget/480015
Below is the code I don't get, it's not working as shown in the video .. The answer I should be getting according to Udacity is [0, 0, 1, 0, 0] Here is what I get []
p=[0, 1, 0, 0, 0] def move(p, U): q = [] for i in range(len(p)): q.append(p[(i-U) % len(p)]) return q print move(p, 1)最满意答案
压痕问题 。 你应该在for循环之外移动你的return语句,否则它会在第一次迭代后立即返回: -
for i in range(len(p)): q.append(p[(i-U) % len(p)]) return q而且,您的原始代码返回[0]而不仅仅是[] 。
Indentation problem. You should move your return statement outside the for loop, else it will return immediately after the first iteration: -
for i in range(len(p)): q.append(p[(i-U) % len(p)]) return qAnd also, your original code returns [0] and not just [].
更多推荐
发布评论