A Smarter Way to Learn Python / Chapter 56 Exercises

  • Index of exercises
  • Email me

1

2

3

4

5

6

7

8

9

10

11

12

 

Congratulations. You've aced all the exercises for this chapter.


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.


  All of my books include free interactive online exercises that make the knowledge stick.

A Smarter Way to Learn JavaScript
Shop for it at Amazon
A Smarter Way to Learn HTML and CSS
Shop for it at Amazon
A Smarter Way to Learn jQuery
Shop for it at Amazon

copyright © 2017 by Mark Myers. All rights reserved.

0,1,2,3,4,5,6,7,8,9,10,11

0

0

0

0


Fill in the blank to create an instance of the class Customer. Make up the name of the instance. ______ = Customer("Hedaya") customer_898^ *[a-zA-Z_][a-zA-Z0-9_]* *$
Fill in the blank to create an instance. The value is "blue". SKU101 = Product_____ ("blue")^ *\(•blue•\) *$
Create an instance of this class. The name of the instance is geneva. The value is 144. class Lake():
  def __init__(self, depth):
    self.depth = depth
geneva = Lake(144) geneva `= `Lake`(`144`)
Create an instance of this class. The name of the instance is dog. The value is "canine". class Animal():
  def __init__(self, species):
    self.species = species
dog = Animal("canine")dog = Animal("canine")
Create an instance of this class. Make up the name of the instance and the value. The value can be a string or an integer. class Student():
  def __init__(self, grade):
    self.grade = grade
student_id_325 = Student("B+") ^ *[a-zA-Z_][a-zA-Z0-9_]* = Student\(•.+•|-?[0-9]+\) *$
Code the first two lines of a class definition. Make up the class name and attribute name. class Industry():
  def __init__(self, revenue):
^ *class [A-Z][a-zA-Z0-9_]*\(\):\n def __init__\(self, [a-zA-Z_][a-zA-Z0-9_]*\): *$
Code an instance of this class. The value is a Boolean. Make up the name of the instance. Your choice of Boolean. class Student(): student_974 = Student(True) ^ *[a-zA-Z_][a-zA-Z0-9_]* = Student\(True|False\) *$
Code the second and third lines of a class definition. Make up the attribute name. Indent correctly.   def __init__(self, parent):
    self.parent = parent
^ *def __init__\(self, ([a-zA-Z_][a-zA-Z0-9_]*)\):\n *self\.\1 = \1 *$
Code an instance of a class. The value is a variable. Make up the name of the instance, the class name, and the variable name. area12 = Suspect_area(region_3) ^ *[a-zA-Z_][a-zA-Z0-9_]* = [A-Z][a-zA-Z0-9_]*\([a-zA-Z_][a-zA-Z0-9_]*\) *$
Code a class definition. Then create an instance of it. Make everything up. The value can be a string, number, Boolean, or variable. class Character():
  def __init__(self, motivation):
    self.motivation = motivation
othello = Character("revenge")
^ *class ([A-Z][a-zA-Z0-9_]*)\(\):\n def __init__\(self, ([a-zA-Z_][a-zA-Z0-9_]*)\):\n self\.\2 = \2\n[a-zA-Z_][a-zA-Z0-9_]* = \1\(•.+•|True|False|-?[0-9]+|[-]?(?:[.]\d+|\d+(?:[.]\d*)?)\) *$
  1. Code an instance of the class.
  2. Display the instance.
  3. Click the Run button   above your code. If you've coded correctly, something like <__main__.Product object at 0x7f2fd2bac470> will display in the right-hand panel. (You can click Instructions at the top of the right-hand panel to see the correct code.)
f57abaa291
  1. Code a class.
  2. Code an instance of the class.
  3. Display the instance.
  4. Click the Run button   above your code. If you've coded correctly, something like <__main__.Product object at 0x7f2fd2bac470> will display in the right-hand panel. (You can click Instructions at the top of the right-hand panel to see the correct code.)
7280f2db9e