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
This is the first line of a method. Fill in the blank. | def calc(______): | self | ^ *self *$ |
This is the first line of a method. Fill in the blank. | def say_if_minor________ | (self): | ^ *\(self\): *$ |
Code the first line of a method. Its name is whatever. | def whatever(self): | def `whatever`(`self`)`: | |
Code the first line of a method. Its name is x. Start by indenting. | def x(self): | def x(self): | |
Code the first line of a method. Make up the name of the method. Indent. | def calc(self): | ^ * def [a-zA-Z_][a-zA-Z0-9_]*\(self\): *$ | |
Code the second line of a method. Display the name attribute of the instance. Indent two tabs. | print(self.name) | ^ * print\(self\.name\) *$ | |
Code the first two lines of a method. It displays an attribute of the instance. Make up the name of the method and the name of the attribute. Indent the first line. Indent the second line two tabs. | def show(self): print(self.price) |
^ * def [a-zA-Z_][a-zA-Z0-9_]*\(self\):\n print\(self\.[a-zA-Z_][a-zA-Z0-9_]*\) *$ | |
Code a method. If the age attribute of the instance equals the height attribute of the instance, display a message. Make up what you need to. Indent correctly, starting with the first line. | def compare(self): if self.age == self.height: print("Old adult!") |
^ * def [a-zA-Z_][a-zA-Z0-9_]*\(self\):\n if self\.age == self\.height:\n print\(•.+•\) *$ | |
Code a method. Concatenate two attributes and assign the combination to a variable. Make everything up. Begin by indenting. | def combine(self): combination = self.first + self.last |
^ * def [a-zA-Z_][a-zA-Z0-9_]*\(self\):\n [a-zA-Z_][a-zA-Z0-9_]* = self\.[a-zA-Z_][a-zA-Z0-9_]* \+ self\.[a-zA-Z_][a-zA-Z0-9_]* *$ | |
Code the first four lines of a class definition. It has one attribute. The fourth line—and the last one that you're going to code—is the first line of a method. Make everything up. Indent correctly. | class Customer(): def __init__(self, age): self.age = age def check_age(self): |
^ *class [A-Z][a-zA-Z0-9_]*\(\):\n def __init__\(self, ([a-zA-Z_][a-zA-Z0-9_]*)\):\n self\.\1 = \1\n def [a-zA-Z_][a-zA-Z0-9_]*\(self\): *$ | |
|
dcfd71c5b7 | ||
|
e30eb0b8e4 |