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


Which is the attribute in the following code? class Patient():
  def __init__(self, name):
name^ *name *$
Fill in the blank at the beginning of the line.   ____ __init__(self, name): def^ *def *$
Complete the line. The attribute is name.   def __init__(____________self, name): self`, `name`)`:
Type the two characters that come immediately before and immediately after init. ____
Type the word that has two underlines before and two underlines after it. init ^ *init *$
Type the word that begins the second line of a class definition. def ^ *def *$
Type all the characters that come before the opening parenthesis in the definition of an attribute. def __init__ ^ *def __init__ *$
Type all the characters up to and including the comma. def __init__(self, ^ *def __init__\(self, *$
Code the second line of a class definition. Make up the attribute name. No need to indent. def __init__(self, age): ^ *def __init__\(self, [a-zA-Z_][a-zA-Z0-9_]*\): *$
Code the first two lines of a class definition. Make up the names. Remember to capitalize the class name and to indent the second line. class House():
  def __init__(self, price):
^ *class [A-Z][a-zA-Z0-9_]*\(\):\n def __init__\(self, [a-zA-Z_][a-zA-Z0-9_]*\): *$
  1. We're not ready to live-code a class definition yet, so let's review earlier material: Slice consecutive elements out of this list to create a new list, female_friends. The elements of the new list will be "Rachel", "Monica", and "Phoebe".
  2. Display the new list.
  3. Click the Run button   above your code. If you've coded correctly, the new list with the three female names will display in the right-hand panel. (You can click Instructions at the top of the right-hand panel to see the correct code.)
0bf8a86f54
  1. Pop "Gunther" off the list and assign it to a variable.
  2. Display the variable.
  3. Click the Run button   above your code. If you've coded correctly, the Gunther will display in the right-hand panel. (You can click Instructions at the top of the right-hand panel to see the correct code.)
8ab88f2a7f