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


When you read a CSV file in Python, you loop through it to turn it into a _______ list^ *list *$
You pick an element out of a list by specifying its ______ (one word) index
Complete the line to find the index number of "Bulgaria" in the list. index_to_find = country_list.index_______________("Bulgaria") (`"`Bulgaria`"`)
Complete the line to find the index number of "bat" in the list. x = animals_________________.index("bat").index("bat")
Complete the line to find the index of "vodka" in the drinks list. i = _________________________________ drinks.index("vodka") ^ *drinks\.index\(•vodka•\) *$
Find the index of a string in a list and assign it to a variable. Make everything up. target = drinks.index("vodka") ^ *[a-zA-Z_][a-zA-Z0-9_]* = [a-zA-Z_][a-zA-Z0-9_]*\.index\(•.+•\) *$
In a single line display the index of a string in a list. Make everything up. print(drinks.index("gin")) ^ *print\([a-zA-Z_][a-zA-Z0-9_]*\.index\(•.+•\)\) *$
You're looking for the index of "Brian" in the following list, whose name is people. Write the first line. Make up the name of the variable that holds the index number. ["First name","Last name","Age","Brian","Obst","36"] target = people.index("Brian") [a-zA-Z_][a-zA-Z0-9_]* = people.index\(•Brian•\)
You're looking for Brian's age in the people list: ["First name","Last name","Age","Brian","Obst","36"]. Complete the second line using the variable from the first line. target = people.index("Brian")
targets_age_index = ____________
target + 2 ^ *target \+ 2 *$
This is the people list: ["First name","Last name","Age","Brian","Obst","36"]. Code three lines that find the first name of the person named Obst and assign the first name to a variable. Make everything up. index_of_last_name = people.index("Obst")
index_of_first_name = index_of_last_name - 1
first_name = people[index_of_first_name]
^ *([a-zA-Z_][a-zA-Z0-9_]*) = people\.index\(•Obst•\)\n([a-zA-Z_][a-zA-Z0-9_]*) = \1 - 1\n[a-zA-Z_][a-zA-Z0-9_]* = people\[\2\] *$
  1. This is the first line of the potions.csv file on your Desktop: Potion,Effect,Telltale Property. In IDLE code a Python program that...
  2. ...reads the potions.csv file and converts it to a list...
  3. ...finds the effect of "Draught of Peace"...
  4. ...and displays the effect.
Note: the lines following the conversion to a list are not indented.