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
In Python a ______ is a template for organizing multiple instances of information, similar to a paper form. | class | ^ *class *$ | |
Rewrite this first line of a class definition so it follows conventional style. | class product(): | class Product(): | ^ *class Product\(\): *$ |
Complete this first line of a class definition. | class Country____ | (): | (`)`: |
Rewrite this first line of a class definition so it's valid. | class Customer = (): | class Customer(): | class Customer(): |
Code the first line of a class definition. The class is named Animal. | class Animal(): | ^ *class Animal\(\): *$ | |
Code the first line of a class definition. Make up the name. | class Patient(): | ^ *class [A-Z][a-zA-Z0-9_]*\(\): *$ | |
Code the first two lines of a function. Line 2 begins the definition of a class. Make everything up. | def start_a_class_definition(): class Secret_info(): |
^ *def [a-zA-Z_][a-zA-Z0-9_]*\(\):\n class [A-Z][a-zA-Z0-9_]*\(\): *$ | |
That's it for this chapter's exercises. The last three questions will review previous chapters. Rewrite the following code using a nested if statement. | if a == b and c == d: match = True |
if a == b: if c == d: match = True |
^ *if a == b:\n if c == d:\n match = True *$ |
Code a list that contains one dictionary. The dictionary contains one item. Both the key and value are strings. Code it in five lines. Make everything up. | relatives = [ { "wife": "Angie", }, ] |
^ *[a-zA-Z_][a-zA-Z0-9_]* = \[\n {\n •.+•: •.+•,?\n },?\n\] *$ | |
In a single line, target the correct list, dictionary, and key to display Leopold. | relatives = [ { "wife": "Angie", }, { "brother": "Leopold", }, { "cousin": "Beltran", }, ] |
print(relatives[1]["brother"]) | ^ *print\(relatives\[1\]\[•brother•\]\) *$ |
|
9d4bc29a70 | ||
|
c9430aec28 |