The multiple choice questions here are intended for the section on (python loops)[http://swcarpentry.github.io/python-novice-inflammation/02-loop.html]
How would you create a loop to iterate over the contents of the list `mylist = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] and print out each element ?
- for item in range(mylist): print(item)
- for item in range(len(mylist)): print(item)
- for item in mylist: print(item)
- for item in mylist print(item)
You have a list which contains ten elements. Which of the following uses of range() would produce a list of the indexes in the list?
- Answer ‘a’ forgets that lists are counted from zero.
- Answer ‘b’ is the correct answer
- Answer ‘c’ forgets that range counts up to, but not including the maximum, so that len(mylist) does the right thing
- Answer ‘d’ is a combination of errors ‘a’ and ‘c’