Resources for the second edition are here. I'd love to know what you think about Python Crash Course; please consider taking a brief survey. If you'd like to know when additional resources are available, you can sign up for email notifications here. Show
Solutions - Chapter 6
Back to solutions. 6-1: PersonUse a dictionary to store information about a person you know. Store their first name, last name, age, and the city in which they live. You should have keys such as
Output: top 6-2: Favorite NumbersUse a dictionary to store people’s favorite numbers. Think of five names, and use them as keys in your dictionary. Think of a favorite number for each person, and store each as a value in your dictionary. Print each person’s name and their favorite number. For even more fun, poll a few friends and get some actual data for your program.
Output:
top 6-3: GlossaryA Python dictionary can be used to model an actual dictionary. However, to avoid confusion, let’s call it a glossary.
Output:
top 6-4: Glossary 2Now that you know how to loop through a dictionary, clean up the code from Exercise 6-3 (page 102) by replacing your series of
Output:
top 6-5: RiversMake a dictionary containing three major rivers and the country each river runs through. One key-value pair might be
Output*:
*Sometimes we like to think of Alaska as our own separate country. top 6-6: PollingUse the code in favorite_languages.py (page 104).
Output:
top 6-7: PeopleStart with the program you wrote for Exercise 6-1 (page 102). Make two new dictionaries representing different people, and store all three dictionaries in a list called
Output:
top 6-8: PetsMake several dictionaries, where the name of each dictionary is the name of a pet. In each dictionary, include the kind of animal and the owner’s name. Store these dictionaries in a list called Note: When I decided to post solutions and wrote complete programs to solve each exercise, I realized this problem was not as well phrased as it should have been. It doesn’t really make sense to name each dictionary for the pet it describes; that information should really be included in the dictionary, rather than being used as the name of the dictionary. This solution reflects that approach.
Output:
top 6-9: Favorite PlacesMake a dictionary called
Output:
top 6-10: Favorite NumbersModify your program from Exercise 6-2 (page 102) so each person can have more than one favorite number. Then print each person’s name along with their favorite numbers.
Output:
top 6-11: CitiesMake a dictionary called
Output:
top What are the four major rivers in Canada?The list is ordered by the river's total length, not just the portions within Canadian borders.. Mackenzie River: 4,241 km. Mackenzie River. ... . Yukon River: 3,185 km. ... . Nelson River: 2,575 km. ... . Columbia River: 2,000 km. ... . Saskatchewan River: 1,939 km. ... . Peace River: 1,923 km. ... . South Saskatchewan River: 1,392 km. ... . Fraser River: 1,375 km.. How many major rivers does Canada have?Mackenzie, Yukon, St. Lawrence, Columbia, and Saskatchewan are among the five major Canadian rivers. These are also the top 5 longest Canadian rivers in the descending order.
What are the name of the two major rivers in Canada?Table
What are major waters in Canada?The illustration shows that the largest lakes in Canada are as follows: Lake Melville, Newfoundland: 3200 square kilometres Amadjuak Lake, Nunavut: 3200 square kilometres Lake of the Woods, Ontario and Manitoba (Canadian portion): 3300 square kilometres Dubawnt, Northwest Territories: 3800 square kilometres Lake ...
|