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


In this code, customer_29876 is a ______. (one word)  if "brother-in-law" in customer_29876["discounts"]:
   discount_amount = .30
 elif "loyalty" in customer_29876["discounts"]:
   discount_amount = .15
dictionary^ *dictionary *$
In this code, "discounts" is a ______. (one word)  if "brother-in-law" in customer_29876["discounts"]:
   discount_amount = .30
 elif "loyalty" in customer_29876["discounts"]:
   discount_amount = .15
list^ *list *$
To check whether "spanner" is in the "wrenches" list inside the tools dictionary, complete the line.   if "spanner" in ______________tools["wrenches"]: tools`[`"`wrenches`"`]`:
To check whether "weaving" is in the "electives" list inside the courses dictionary, complete the line. if "weaving" in courses["electives"]:if "weaving" in courses["electives"]:
Check whether "Mary" is in the "enrolled" list inside the students dictionary. if "Mary" in students["enrolled"]: ^ *if •Mary• in students\[•enrolled•\]: *$
Check whether "Marx" is in a list within a dictionary. Make up the list and dictionary names. if "Marx" in thinkers["left-wing"]: ^ *if •Marx• in [a-zA-Z_][a-zA-Z0-9_]*\[•?.+•?\]: *$
Test whether an integer is in a list within a dictionary. Make everything up. if 666 in numbers["evil"]: ^ *if -?[0-9]+ in [a-zA-Z_][a-zA-Z0-9_]*\[•?.+•?\]: *$
Test whether "red" is in the list within the dictionary. specs = {
  "colors": ["green", "blue", "purple"],
}
if "red" in specs["colors"]: ^ *if •red• in specs\[•colors•\]: *$
Test whether a color is in the list within the dictionary. Make up the color. specs = {
  "colors": ["green", "blue", "purple"],
}
if "red" in specs["colors"]: ^ *if •.+• in specs\[•colors•\]: *$
Test whether a color is in the list within the dictionary. If so, display "first". If not, test whether another color is in the list. If so, display "second". Your choice of colors. specs = {
  "colors": ["green", "blue", "purple"],
}
if "red" in specs["colors"]:
  print("first")
elif "blue" in specs["colors"]:
  print("second")
^ *if •.+• in specs\[•colors•\]:\n print\(•first•\)\nelif •.+• in specs\[•colors•\]:\n print\(•second•\) *$
  1. Test whether a particular career is in the list. If so, display "yes". If not, display "no".
  2. Click the Run button   above your code. If you've coded correctly, yes or no will display in the right-hand panel. (You can click Instructions at the top of the right-hand panel to see the correct code.)
affcf70b5d
  1. If he is married and has "rock star" in his career list, display "Uh-oh".
  2. Click the Run button   above your code. If you've coded correctly, Uh-oh will display in the right-hand panel. (You can click Instructions at the top of the right-hand panel to see the correct code.)
9345eb8a10