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


What is this? (one word) def greeting():
  print("Hello, World!")
function^ *function *$
There's a mistake in the second line. It should be _________. (one word) def greeting():
print("Hello, World!")
indented^ *indented *$
Type the last three characters of this line. def greeting____(): (`)`:
Type the first three characters of this function definition. ___ greeting():defdef
Code the first line of a function definition. Make up the name of the function. (Remember, the name of a function has to be a legal variable name.) def add_numbers(): ^ *def [a-zA-Z_][a-zA-Z0-9_]*\(\): *$
Turn this code into a function. Make up the name of the function. Remember to indent correctly. total = 2 + 2 def add_em():
  total = 2 + 2
^ *def [a-zA-Z_][a-zA-Z0-9_]*\(\):\n total = 2 \+ 2 *$
Code a function that displays the concatenation of two strings. Make everything up. def greet_combo():
  print("Hello, " + "World!")
^ *def [a-zA-Z_][a-zA-Z0-9_]*\(\):\n print\(•.+• \+ •.+•\) *$
Call the function named greet. greet() ^ *greet\(\) *$
Code a function that tests whether a equals b and, if so, displays ("ok"). Make up the name of the function. def check():
  if a == b:
    print("ok")
^ *def [a-zA-Z_][a-zA-Z0-9_]*\(\):\n if a == b:\n print\(•ok•\) *$
Call a function. Make up its name. save_the_world() ^ *[a-zA-Z_][a-zA-Z0-9_]*\(\) *$
  1. Turn this line of code into a function. Then call the function.
  2. Click the Run button   above your code. If you've coded correctly, Hello, World! will display in the right-hand panel. (You can click Instructions at the top of the right-hand panel to see the correct code.)
be2b4bf7f3
  1. I've coded a dictionary. Code a function that loops through all the values of the dictionary and displays them.
  2. Call the function.
  3. Click the Run button   above your code. If you've coded correctly, the three values in 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.)
1dd2e2d948