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


If a condition isn't True, it's _______. False^ *False *$
Rewrite this Boolean assignment so it's valid. the_flag = "False" the_flag = False^ *the_flag = False *$
Rewrite this statement using a Boolean instead of the string. while incomplete == "yes":while incomplete == True: while `incomplete `=`= `True`:
Code the first line of an if statement that tests the falsity of today_is_tuesday . if today_is_tuesday == False:if today_is_tuesday == False:
Assign one of the Booleans to a variable. Make everything up. job_complete = True ^ *[a-zA-Z_][a-zA-Z0-9_]* = True|False *$
If one variable is True, a second variable is False. Write the code. Make up the variable names. if x == True:
  y = False
^ *if [a-zA-Z_][a-zA-Z0-9_]* == True:\n [a-zA-Z_][a-zA-Z0-9_]* = False *$
If a variable is False, change it to True. Make up the name of the variable. if x == False:
  x = True
^ *if ([a-zA-Z_][a-zA-Z0-9_]*) == False:\n \1 = True *$
Code a for loop that loops through a list. When an element in the list is False, break the loop. Make up the name of the list and the variable. for an_element in list_of_booleans:
  if an_element == False:
    break
^ *for ([a-zA-Z_][a-zA-Z0-9_]*) in [a-zA-Z_][a-zA-Z0-9_]*:\n if \1 == False:\n break *$
Assign True to a variable. If another variable is True, change the Boolean of the first variable. Make everything up. first_var = True
if second_var == True:
  first_var = False
^ *([a-zA-Z_][a-zA-Z0-9_]*) = True\nif [a-zA-Z_][a-zA-Z0-9_]* == True:\n \1 = False *$
If the sum of two variables equals a third variable and a fourth variable is False, change the fourth variable. Otherwise, add the first variable to itself using concise coding. Make everything up. if a + b == c and d == False:
  d = True
else:
  a += a
^ *if ([a-zA-Z_][a-zA-Z0-9_]*) \+ [a-zA-Z_][a-zA-Z0-9_]* == [a-zA-Z_][a-zA-Z0-9_]* and ([a-zA-Z_][a-zA-Z0-9_]*) == False:\n \2 = True\nelse:\n \1 \+= \1 *$
  1. Assign different Booleans to two variables.
  2. Assign 0 to a third variable.
  3. As long as the two Boolean variables have different values, increment the third variable by 1 and make the first Boolean variable equal to the second Boolean variable.
  4. Display the third variable.
  5. Click the Run button   above your code. If you've coded correctly, 1 will display in the right-hand panel. (You can click Instructions at the top of the right-hand panel to see the correct code.)
745350f57c
  1. Loop through the dictionary. When a value is True, display its key.
  2. Click the Run button   above your code. If you've coded correctly, all the keys except 100 will display in the right-hand panel. Because of a Python technicality, they won't be in order. (You can click Instructions at the top of the right-hand panel to see the correct code.)
81da750f3d