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
It's like a list, but the elements are fixed. What is it called? | tuple | ^ *[T/t]uple *$ | |
Recode this list to make it a tuple. | x = [10, 9] | x = (10, 9) | ^ *x = \(10, 9\) *$ |
Define a tuple with two elements, "hi" and "bye". The tuple's name is greetings. | greetings = ("hi", "bye") | greetings `= `(`"`hi`"`, `"`bye`") | |
Define a tuple with two elements, 1 and 2. The tuple's name is nums. | nums = (1, 2) | nums = (1, 2) | |
Rewrite this so you can make changes to the elements. | sizes = ("sm", "med", "lg", "xl") | sizes = ["sm", "med", "lg", "xl"] | ^ *sizes = \[•sm•, •med•, •lg•, •xl•\] *$ |
Code a tuple with three elements that are numbers. Make up the tuple name and the numbers. | numerical_tuple = (1, 2, 3) | ^ *[a-zA-Z_][a-zA-Z0-9_]* = \([-]?(?:[.]\d+|\d+(?:[.]\d*)?), [-]?(?:[.]\d+|\d+(?:[.]\d*)?), [-]?(?:[.]\d+|\d+(?:[.]\d*)?)\) *$ | |
Concatenate the second element of tuple x with the third element of tuple y. In the concatenation include a comma and space in the middle. Assign the concatenated string to a variable. Make up the variable name. | x = (3, "Hello", "Howdy", "Greetings") y = ("earth", "sun", "World", "Pluto", 144) | greeting = x[1] + ", " + y[2] | ^ *[a-zA-Z_][a-zA-Z0-9_]* = x\[1\] \+ •, • \+ y\[2\] *$ |
Code a tuple with three elements—your first, middle, and last names. Make up the tuple name. | my_names = ("Mark", "Collin", "Myers") | ^ *[a-zA-Z_][a-zA-Z0-9_]* = \(•.*•, •.*•, •.*•\) *$ | |
Code a tuple with three numbers. Make up the tuple name and the numbers. | players = (5, 9, 11) | ^ *[a-zA-Z_][a-zA-Z0-9_]* = \([-]?(?:[.]\d+|\d+(?:[.]\d*)?), [-]?(?:[.]\d+|\d+(?:[.]\d*)?), [-]?(?:[.]\d+|\d+(?:[.]\d*)?)\) *$ | |
Code a tuple with three elements that are strings. Then, in a single line, append the last element to a list. Make up the names and strings. | my_tuple = ("a", "b", "c") my_list.append(my_tuple[2]) | ^ *([a-zA-Z_][a-zA-Z0-9_]*) = \(•.*•, •.*•, •.*•\)\n[a-zA-Z_][a-zA-Z0-9_]*\.append\(\1\[2\]\) *$ | |
| f758cb1e11 | ||
| 5a73f42f34 |