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
Code the next line. Begin by indenting it two tabs. | class Student(): def __init__(self, name, age): self.name = name |
self.age = age | ^ * self\.age = age *$ |
Code the next two lines. Remember to indent. | class Product(): def __init__(self, color, size): |
self.color = color self.size = size | ^ * self\.color = color\n self\.size = size *$ |
These are lines 3 and 4 of a class definition. Code line 2. | self.population = population self.area = area | def __init__(self, population, area): | def `_`_`init`_`_`(`self`, `population`, `area`)`: |
Code the second line of a class definition. It has three attributes—height, weight, and gender. Start by indenting. | def __init__(self, height, weight, gender): | def __init__(self, height, weight, gender): | |
Code the second and third lines of a class definition with one attribute. Make everything up. Remember to indent. | def __init__(self, location): self.location = location |
^ * def __init__\(self, ([a-zA-Z_][a-zA-Z0-9_]*)\):\n self\.\1 = \1 *$ | |
Code an instance of a class that has a single attribute. Its value is a string. Make everything up. | sku_569 = Product("hammer") | ^ *[a-zA-Z_][a-zA-Z0-9_]* = [A-Z][a-zA-Z0-9_]*\(•.+•\) *$ | |
Code a class with two attributes. Make everything up. | class Person(): def __init__(self, nationality, age): self.nationality = nationality self.age = age |
^ *class [A-Z][a-zA-Z0-9_]*\(\):\n def __init__\(self, ([a-zA-Z_][a-zA-Z0-9_]*), ([a-zA-Z_][a-zA-Z0-9_]*)\):\n self\.\1 = \1\n self\.\2 = \2 *$ | |
Code another class with three attributes. Make everything up. | class City(): def __init__(self, nickname, population, mayor): self.nickname = nickname self.population = population self.mayor = mayor |
^ *class [A-Z][a-zA-Z0-9_]*\(\):\n def __init__\(self, ([a-zA-Z_][a-zA-Z0-9_]*), ([a-zA-Z_][a-zA-Z0-9_]*), ([a-zA-Z_][a-zA-Z0-9_]*)\):\n self\.\1 = \1\n self\.\2 = \2\n self\.\3 = \3 *$ | |
Code an instance of a class with three attributes. The first attribute is a string. The second attribute is an integer. The third attribute is a variable. Make everything up. | city956 = City("The City Different", 84000, name) | ^ *[a-zA-Z_][a-zA-Z0-9_]* = [A-Z][a-zA-Z0-9_]*\(•.+•, -?[0-9]+, [a-zA-Z_][a-zA-Z0-9_]*\) *$ | |
Code a class that has two attributes. Then code an instance of the class. Both attributes are strings. Make everything up. | class Animal(): def __init__(self, family, diet): self.family = family self.diet = diet hummingbird = Animal("Trochilidae", "nectar") |
^ *class ([A-Z][a-zA-Z0-9_]*)\(\):\n def __init__\(self, ([a-zA-Z_][a-zA-Z0-9_]*), ([a-zA-Z_][a-zA-Z0-9_]*)\):\n self\.\2 = \2\n self\.\3 = \3\n[a-zA-Z_][a-zA-Z0-9_]* = \1\(•.+•, •.+•\) *$ | |
|
c0be73d90c | ||
|
09c053b342 |