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

There are two correct answers for this one. Answer with either one. What is this?100number or integer^ *number|integer *$
Type the illegal character in this variable name. 2nd_runner_up2^ *2 *$
Assign the number 5 to the variable playersplayers = 5players `= `5
Assign the negative number -6 to the variable lossloss = -6loss = -6
What is the value of total?number = 10
total = number + 2
12^ *12 *$
Assign a number (your choice) to the variable total.total = 15^ *total = [-]?(?:[.]\d+|\d+(?:[.]\d*)?) *$
Assign a negative integer to a variable. You choose the integer and the variable name.loss = -1030^ *.+ = -[0-9]+ *$
What is this (one word, lowercase)?"-8.087"string^ *string *$
Add two variables and assign the result to a third variable. Make up all the variable names.total = merch_total + shipping^ *.* = .* \+ .* *$
Add 5 to the variable running_total and assign the result to the same variablerunning_total = running_total + 5^ *running_total = running_total \+ 5 *$
  1. Click in the left-hand Trinket panel.
  2. On line 1, assign the sum of two numbers to a variable. Make up the variable name and the numbers. On line 2, tell Python to display the sum using the variable.
  3. Click the Run button   above your code. If you've coded correctly, the sum will display in the right-hand panel. (You can click Instructions at the top of the right-hand panel to see the correct code.)
95e5b0c7e4
  1. Click in the left-hand Trinket panel.
  2. I've assigned a number to a variable. On line 2, divide the variable by a number of your choice. Assign the result to a variable of your choice. On line 3, tell Python to display the result using that second variable.
  3. Click the Run button   above your code. If you've coded correctly, the math result will display in the right-hand panel. (You can click Instructions at the top of the right-hand panel to see the correct code.)
9e613e9523