These questions assume a lesson on list comprehensions, with previous knowledge about range() and string methods.
In the following snippet, what is the content of the ‘numbers’ variable?
numbers = [i for i in range(0, 10) if i % 2 == 0]
a) [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
b) [2, 4, 6, 8, 10]
c) [0, 2, 4, 6, 8, 10]
d) [0, 2, 4, 6, 8]
e) [1, 3, 5, 7, 9]
Given the following code snippet , implement the “extract_number” function in a way that matches the output:
def extract_number(note): pass notes = ["c'4", "d2", "g8", "c2", "e16", "f32", "a'8"] for note in notes: print(extract_number(note))
Output:
4 2 8 2 16 32 8