浏览水果列表并打印字符串“我将其添加到我们的产品”中的每一个。参数是“作物名称(字符串)列表,没有返回值。
测试用例
crops = [‘apple’, ‘orange’, ‘banana’, ‘strawberry’]
daysWork(crops)
I added this apple to our produce
I added this orange to our produce
I added this banana to our produce
I added this strawberry to our produce
我的代码:
def daysWork(crops):
for crop in crops:
produce = crops[n]
print 'I added this ' + str(produce) + ' to our produce'
我得到的错误是“错误是:n 全局找不到名称。”
n 不是在每个元素处索引列表吗?