1
2
3
4
5
6
7
8
9
10
11
12
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.
0,1,2,3,4,5,6,7,8,9,10,11
0
0
0
0
What is the keyword for adding a new element to the end of a list? | append | ^ *append *$ | |
Using the append keyword, add the number 1 to the end of the list nums. | nums.append(1) | ^ *nums\.append\(1\) *$ | |
Using the keyword append, add the string "cat" to the end of the list pets. | pets.append("cat") | pets`.`append`(`"`cat`"`) | |
Using the keyword append, add the string "sun" to the end of the list stars. | stars.append("sun") | stars.append("sun") | |
Code the alternative to the following statement, using the plus sign. | x.append(5) | x = x + [5] | ^ *x = x \+ \[5\] *$ |
Using the append keyword, append a string to a list. Make up the string and list name. | oceans.append("Indian Ocean") | ^ *[a-zA-Z_][a-zA-Z0-9_]*\.append\(•.*•\) *$ | |
Using the plus sign instead of append, add two strings to the end of a list. Make up the list name and strings. | cities = cities + ["Dubuque", "New Orleans"] | ^ *([a-zA-Z_][a-zA-Z0-9_]*) = \1 \+ \[•.*•, •.*•\] *$ | |
Insert the number 5 at the beginning of a list. Make up the list name. | nums.insert(0, 5) | ^ *[a-zA-Z_][a-zA-Z0-9_]*\.insert\(0, 5\) *$ | |
In the following list, insert a string after "orange". Make up the string. | fruits = ["apple", "orange", "tangerine", "banana"] | fruits.insert(2, "grape") | ^ *fruits\.insert\(2, •.*•\) *$ |
Using the plus sign rather than append, add two numbers to the end of a list and assign the result to a second list. Make up the list names and the numbers. | longer_list = original_list + [7, 11] | ^ *[a-zA-Z_][a-zA-Z0-9_]* = [a-zA-Z_][a-zA-Z0-9_]* \+ \[[-]?(?:[.]\d+|\d+(?:[.]\d*)?), [-]?(?:[.]\d+|\d+(?:[.]\d*)?)\] *$ | |
| 3e2c2ebc4b | ||
| 556f295c81 |