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


In the following code, the first argument is a _____________ argument. give_greeting("Hello there", first_name="Al") positional^ *positional *$
In the following code, the second argument is a _____________ argument. give_greeting("Hello there", first_name="Al") keyword^ *keyword *$
Call the function concat, providing two positional arguments, x and y. concat(x, y) concat`(`x`, `y`)
Call the function calc, providing x, a positional argument, and a keyword argument. The key is y, the value is 0. calc(x, y = 0)calc(x, y = 0)
Call a function, providing a positional argument first and then a keyword argument. The values of both arguments are variables. Make everything up. calc(multiplier, num = chosen_num) ^ *[a-zA-Z_][a-zA-Z0-9_]*\([a-zA-Z_][a-zA-Z0-9_]*, [a-zA-Z_][a-zA-Z0-9_]* = [a-zA-Z_][a-zA-Z0-9_]*\) *$
Here is the first line of a function and the code that calls it. Rewrite the calling code so it's legal. def calc(first_number, second_number):
calc(second_number = 10, 8)
calc(8, second_number = 10)
The positional argument has to line up
with the positional parameter.
^ *calc\(8, second_number = 10\) *$
Call this function. Override the default. Make up the strings. def combine(first_name, last_name = "Jones"): combine("Tom", last_name = "Smith") ^ *combine\(•.+•, last_name = •.+•\) *$
Call the function name_the_star. The key is star. The value is the value matching "Justified" in the shows dictionary. name_the_star(star = shows["Justified"]) ^ *name_the_star\(star = shows\[•Justified•\]\) *$
Code the first line of a function. The first two parameters are positional, the third parameter is a keyword parameter with a default. The default is an integer. Make everything up. def a(b, c, d = 9): ^ *def [a-zA-Z_][a-zA-Z0-9_]*\([a-zA-Z_][a-zA-Z0-9_]*, [a-zA-Z_][a-zA-Z0-9_]*, [a-zA-Z_][a-zA-Z0-9_]* = -?[0-9]+\): *$
Code a function call. The first and second arguments are positional arguments. The third and fourth arguments are keyword arguments. All values are variables. Make everything up. a(b, c, d = e, f = h) ^ *[a-zA-Z_][a-zA-Z0-9_]*\([a-zA-Z_][a-zA-Z0-9_]*, [a-zA-Z_][a-zA-Z0-9_]*, [a-zA-Z_][a-zA-Z0-9_]* = [a-zA-Z_][a-zA-Z0-9_]*, [a-zA-Z_][a-zA-Z0-9_]* = [a-zA-Z_][a-zA-Z0-9_]*\) *$
  1. Code a function that does a math operation on two parameters and displays the result.
  2. Call the function. The first argument is a positional argument. The second argument is a keyword argument.
  3. Click the Run button   above your code. If you've coded correctly, the result of the functions math will display in the right-hand panel. (You can click Instructions at the top of the right-hand panel to see the correct code.)
962c97e6c8
  1. Code a function with two parameters that have defaults. The function displays the parameters on separate lines.
  2. Call the function, overriding both defaults.
  3. Click the Run button   above your code. If you've coded correctly, the values provided by the calling code arguments will display in the right-hand panel. (You can click Instructions at the top of the right-hand panel to see the correct code.)
f5704cbf54