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


A function within a class definition is a _______. method^ *method *$
In the following code, the part after the dot is the method call. What is the part before the dot? (1 word) prod88.calc() instance^ *.*instance *$
Call the method named analyze for the instance named i9877 i9877.analyze() i9877`.`analyze`(`)
Call the method named eval for the instance named score score.eval()score.eval()
Call a method. Make up the name of the instance and the name of the method. score.eval() ^ *[a-zA-Z_][a-zA-Z0-9_]*\.[a-zA-Z_][a-zA-Z0-9_]*\(\) *$
Re-code this function call as a method call. capitalize(a4056.first_name, a4056.last_name) a4056.capitalize() ^ *a4056\.capitalize\(\) *$
Code a method call with a single positional argument that's a string. Make everything up. cust4056.check_status("Cairo") ^ *[a-zA-Z_][a-zA-Z0-9_]*\.[a-zA-Z_][a-zA-Z0-9_]*\(•.+•\) *$
Code a method call with two arguments. The first is a positional argument that's an integer. The second argument is a keyword argument whose value is an integer. Make everything up. cust4056.check_status(50987, flight_number = 1038) ^ *[a-zA-Z_][a-zA-Z0-9_]*\.[a-zA-Z_][a-zA-Z0-9_]*\(-?[0-9]+, [a-zA-Z_][a-zA-Z0-9_]* = -?[0-9]+\) *$
The method calc returns a value. Call it, assigning the returned value to a variable. Make up the name of the instance and the name of the variable. total = order1050.calc() ^ *[a-zA-Z_][a-zA-Z0-9_]* = [a-zA-Z_][a-zA-Z0-9_]*\.calc\(\) *$
In a single line display the value returned by a method call. Make everything up. print(cust777.calc()) ^ *print\([a-zA-Z_][a-zA-Z0-9_]*\.[a-zA-Z_][a-zA-Z0-9_]*\(\)\) *$
  1. Call the freestanding function say_if_minor. Provide the name of the instance and the attribute name as the argument.
  2. Click the Run button   above your code. If you've coded correctly, This patient is a minor will display in the right-hand panel. (You can click Instructions at the top of the right-hand panel to see the correct code.)
f30f98d8cd
  1. Call the method say_if_minor for the instance.
  2. Click the Run button   above your code. If you've coded correctly, This patient is a minor will display in the right-hand panel. (You can click Instructions at the top of the right-hand panel to see the correct code.)
2327389957