A Smarter Way to Learn Python / Chapter 39 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 the following code, 0 is the name of a _________. customers = {
  0: [
list^ *list *$
In the following code, 0 is the name of a _________. customers = {
  0: {
dictionary^ *dictionary *$
The first pair in the 0 dictionary is "first name" and "John". Fill in the blank. Remember to end the line with a comma. customers = {
  0: {
        _________________
"first name": "John", "`first name`"`: `"`John`"`,
Code the next line. The dictionary name is 0. Remember to indent. customers = {  0: { 0: {
Code the first two lines of a dictionary within a dictionary. The inner dictionary name is 0. Make up the name of the outer dictionary. Remember to indent the second line. products = {
  0: {
^ *[a-zA-Z_][a-zA-Z0-9_]* = {\n 0: { *$
The first pair in the 0 dictionary is "wrench" and 9.37. Code the line. Remember to double-indent it and to end the line with a comma. products = {
  0: {
    "wrench": 9.37, ^ * •wrench•: 9\.37, *$
The next pair is "saw" and 23.47. Code the line, then close the 0 dictionary. Pay attention to the indents. End both lines with a comma. products = {
  0: {
    "wrench": 9.37,
    "saw": 23.47,
  },
^ * •saw•: 23\.47,\n }, *$
Code the first two lines of a dictionary that includes an inner dictionary. The name of the outer dictionary is a variable. The name of the inner dictionary is an integer. Make everything up. ranking_nations = {
  99: {
^ *[a-zA-Z_][a-zA-Z0-9_]* = {\n -?[0-9]+: { *$
Code a complete dictionary that includes nothing but one inner dictionary. The name of the outer dictionary is a variable. The name of the inner dictionary is an integer. The inner dictionary contains only one pair, a string key and a string value. Make everything up. x = {
  0: {
    "name": "Ortiz",
  },
}
^ *[a-zA-Z_][a-zA-Z0-9_]* = {\n -?[0-9]+: {\n •.+•: •.+•,\n },\n} *$
Add a second inner dictionary, then close both the inner and outer dictionaries. The dictionary's name is 1. It contains just one pair. Its key is "name". Make up the value, a string. x = {
  0: {
    "name": "Ortiz",
  },
  1: {
    "name": "Ng",
  },
}
^ * 1: {\n •name•: •.+•,\n },\n} *$
  1. Code a dictionary that contains an inner dictionary with at least one pair, then display it.
  2. Click the Run button   above your code. If you've coded correctly, the dictionary including the inner dictionary will display in the right-hand panel. (You can click Instructions at the top of the right-hand panel to see the correct code.)
bbb26c2330
  1. Code a dictionary and display it. The dictionary contains a list and another dictionary. The list has at least two elements, the dictionary has at least two pairs.
  2. Click the Run button   above your code. If you've coded correctly, the dictionary will display in the right-hand panel. (You can click Instructions at the top of the right-hand panel to see the correct code.)
bc8b92ea8e