A Smarter Way to Learn Python / Chapter 55 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


This is the third line of a class definition. Fill in the blank. _______last_name = last_name self.^ *self\. *$
Code the first line of a class definition. Make up the class name. Remember to start the class name with an uppercase letter. class Patient():^ *class [A-Z][a-zA-Z0-9_]*\(\): *$
Code the second line of a class definition. The attribute is price. def __init__(self, price): def `_`_`init`_`_`(`self`, `price`)`:
Code the second line of a class definition. The attribute is area. Don't bother to indent it for this exercise. def __init__(self, area):def __init__(self, area):
Fill in the blank. self.last_name = __________ last_name ^ *last_name *$
Fill in the blank.   def __init__(self, last_name):
    ____________ = last_name
self.last_name ^ *self\.last_name *$
Code the next line. Remember to indent it two tabs.   def __init__(self, salary):     self.salary = salary ^ *self\.salary = salary *$
Code the first and second lines of a class definition. Make up the class and attribute names. class Ocean():
  def __init__(self, area):
^ *class [A-Z][a-zA-Z0-9_]*\(\):\n def __init__\(self, [a-zA-Z_][a-zA-Z0-9_]*\): *$
Code lines 2 and 3 of a class definition. Make up the attribute name. Start by indenting.   def __init__(self, size):
    self.size = size
^ *def __init__\(self, ([a-zA-Z_][a-zA-Z0-9_]*)\):\n *self\.\1 = \1 *$
Code a three-line class definition. Make up the class and attribute names. Remember to indent. class Car():
  def __init__(self, price):
    self.price = price
^ *class [A-Z][a-zA-Z0-9_]*\(\):\n def __init__\(self, ([a-zA-Z_][a-zA-Z0-9_]*)\):\n self\.\1 = \1 *$
  1. We're still reviewing previous chapters. In a single line of code, target "Sattermyer" in the dictionary and display it.
  2. Click the Run button   above your code. If you've coded correctly, Sattermyer will display in the right-hand panel. (You can click Instructions at the top of the right-hand panel to see the correct code.)
682576bc68
  1. Delete the first inner dictionary.
  2. Change Jill Somers' last name to Barns
  3. Display the customers dictionary.
  4. Click the Run button   above your code. If you've coded correctly, the customer dictionary, with two inner dictionaries and a changed last name for Jill Somers, will display in the right-hand panel. (You can click Instructions at the top of the right-hand panel to see the correct code.)
de6f18e1ca