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


Get an element in a list and assign it to a variable. Make everything up. the_element = a_list[7]^ *[a-zA-Z_][a-zA-Z0-9_]* = [a-zA-Z_][a-zA-Z0-9_]*\[-?[0-9]+\] *$
Get a value in a dictionary and assign it to a variable. The key is a string. price_to_get = product_3278["price"]^ *[a-zA-Z_][a-zA-Z0-9_]* = [a-zA-Z_][a-zA-Z0-9_]*\[•.+•\] *$
In a single line, display the element in the animals whose index is 3. print(animals[3]) print`(`animals`[`3`]`)
In a single line, display the value in the animals dictionary's whose key is "wings". print(animals["wings"])print(animals["wings"])
The animals list contains dictionaries. Get a value out of dictionary 76 and assign it to a variable. The key is "name". Make up the variable name. targeted_name = animals[76]["name"] ^ *[a-zA-Z_][a-zA-Z0-9_]* = animals\[76\]\[•name•\] *$
The animals dictionary contains lists. Get an element out of the "9" list that has an index of 0 and assign it to a variable. Make up the variable name. target = animals["9"][0] ^ *[a-zA-Z_][a-zA-Z0-9_]* = animals\[•9•\]\[0\] *$
The dictionary flowers contains a dictionary whose name is 43. Get the value out of the dictionary whose key is a string and assign it to a variable. Make up the names of the key and the variable. target = flowers[43]["annual"] ^ *[a-zA-Z_][a-zA-Z0-9_]* = flowers\[43\]\[•.+•\] *$
The dictionary students contains a dictionary whose name is 340. Get the value out of the dictionary whose key is a number and assign it to a variable. Make up the names of the key and the variable. course = students[340][3] ^ *[a-zA-Z_][a-zA-Z0-9_]* = students\[340\]\[-?[0-9]+\] *$
Find the number of pairs in the students dictionary and assign the number to a variable. Make up the variable name. enrollment = len(students) ^ *[a-zA-Z_][a-zA-Z0-9_]* = len\(students\) *$
The dictionary students contains a dictionary whose name is 340. Find the number of pairs in the 340 dictionary and assign the number to a variable. Make up the variable name. target = len(students[340]) ^ *[a-zA-Z_][a-zA-Z0-9_]* = len\(students\[340\]\) *$
  1. In a single statement, target one of the values in one of the inner dictionaries and display it.
  2. Click the Run button   above your code. If you've coded correctly, the targeted value will display in the right-hand panel. (You can click Instructions at the top of the right-hand panel to see the correct code.)
4bfa2a7aef
  1. In a single statement, select the correct target in the inner dictionary and display it so Wei shows up in the right-hand results panel.
  2. Click the Run button   above your code. If you've coded correctly, Wei will display in the right-hand panel. (You can click Instructions at the top of the right-hand panel to see the correct code.)
ace675b061