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


Complete the line to begin coding a list of dictionaries. (3 characters) customers _____ = [^ *= \[ *$
The name of the list of dictionaries is customers. Code the first line. customers = [^ *customers = \[ *$
The name of the list of dictionaries is list_of_dictionaries. Code the first line. list_of_dictionaries = [ list_of_dictionaries `= `[
Code the second line. Remember to indent it. products = [  { {
Code the first three lines of a list of dictionaries. Its keys and values are strings. Make up the other names. Remember to indent correctly and add a comma after the key-value pair. things_i_love = [
  {
    "fish": "Sam",
^ *[a-zA-Z_][a-zA-Z0-9_]* = \[\n {\n •.+•: •.+•, *$
Code the first three lines of a list of dictionaries. The dictionary's keys and values are numbers. Make everything else up. combos = [
  {
    12: 144,
^ *[a-zA-Z_][a-zA-Z0-9_]* = \[\n {\n -?[0-9]+: -?[0-9]+, *$
Code the first three lines of a list of dictionaries. The dictionary's keys are strings and its values are numbers. Make everything else up. stats = [
  {
    "China": 2,
^ *[a-zA-Z_][a-zA-Z0-9_]* = \[\n {\n •.+•: [-]?(?:[.]\d+|\d+(?:[.]\d*)?), *$
I've coded the first line of a list of dictionaries. Code the first dictionary in the list. It has just two items. Both keys and values are strings. Make everything up. Remember to indent correctly. Remember to include the comma at the end. performers = [   {
    "pianist": "Serkin",
    "violinist": "Hahn",
  },
^ * {\n •.+•: •.+•,\n •.+•: •.+•,\n }, *$
I've coded the first line of a list of dictionaries. Code the first dictionary in the list. It has just two items. Keys are numbers, values are strings. Make everything up. Remember to include the comma at the end. ranks = [   {
    1: "Ho",
    2: "Park",
  },
^ * {\n -?[0-9]+: •.+•,\n -?[0-9]+: •.+•,\n }, *$
Code a list containing two dictionaries. Each dictionary has two key-value pairs. All keys and values are numbers. Make everything up. relationships = [
  {
    4: 16,
    3: 9,
  },
  {
    50: 100,
    100: 200,
  },
]
^ *[a-zA-Z_][a-zA-Z0-9_]* = \[\n {\n -?[0-9]+: -?[0-9]+,\n -?[0-9]+: -?[0-9]+,\n },\n {\n -?[0-9]+: -?[0-9]+,\n -?[0-9]+: -?[0-9]+,\n },\n\] *$
  1. Code a list containing just one dictionary. The dictionary contains just one key-value pair. Display the dictionary.
  2. Click the Run button   above your code. If you've coded correctly, the list, including 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.)
f812da803b
  1. Code a list that contains two dictionaries. Each dictionary contains two key-value pairs. Display the list. Important: Remember to add a comma after each curly bracket that closes a dictionary (}).
  2. Click the Run button   above your code. If you've coded correctly, the list including both dictionaries will display in the right-hand panel. (You can click Instructions at the top of the right-hand panel to see the correct code.)
bd9bb20763