To practice on your own, or to check code you believe shouldn't have been scored as incorrect, go to Trinket.
Post a review on Amazon for the paperback or the Kindle edition.
Email me to give me a compliment, complaint, or correction. I'll respond.
|In the following code, smaller_list_of_cities is assigned __ elements of the cities list. (Enter a numeral.)||smaller_list_of_cities = cities[2:5]||The answer is 3. 2:5 means elements with indexes of 2, 3, and 4||^ *3 *$|
|Fill in the blank. The first element in the slice is the second element in the list. The last element in the slice is the third element in the list.||smaller_list_of_cities = cities[____]||1:3 — the 3 here is the index number of the element|
that comes after the last element
in the slice. The slice is elements 1 through 2.
|^ *1:3 *$|
|Copy the second through eighth elements from the list y and assign the slice to the list x.||x = y[1:8]||x `= `y`[`1`:`8`]|
|Reduce the list x to a slice of itself—the sixth through 8th elements.||x = x[5:8]||x = x[5:8]|
|Copy some elements from a list and assign the slice to another list. Make up the list names and the index numbers.||x = y[2:14]||^ *[a-zA-Z_][a-zA-Z0-9_]* = [a-zA-Z_][a-zA-Z0-9_]*\[[0-9]+:[0-9]+\] *$|
|What is the index number of the last element in the slice?||x = y[7:9]||8||^ *8 *$|
|Fill in the blank to slice the first through ninth element with minimal coding.||x = y[____]||:9||^ *:9 *$|
|Using minimal coding, copy the fifth through last element from y and assign the slice to x.||x = y[4:]||^ *x = y\[4:\] *$|
|Copy the numbers 2 through 4 out of y and assign the slice to x.||y = [1, 2, 3, 4, 5]||x = y[1:4]||^ *x = y\[1:4\] *$|
|Using minimal coding, reduce the list x to its first five elements.||x = x[:5]||^ *x = x\[:5\] *$|