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

Rewrite this so total equals 10.total = "4" + 6total = 4 + 6^ *total = 4 \+ 6 *$
What is the value of third_number?first_number = 5
second_number = 6
third_number = first_number * second_number
30^ *30 *$
Divide 12 by the decimal .5 and assign the result to the variable outcomeoutcome = 12 / .5outcome `= `12 `/ `.5
Divide the variable total by 3 and assign the result to the variable each_share.each_share = total / 3each_share = total / 3
Subtract one number from another and assign the result to a variable. Make up the numbers and the variable name.left_over = 1345 - 801^ *.* = [-]?(?:[.]\d+|\d+(?:[.]\d*)?) - [-]?(?:[.]\d+|\d+(?:[.]\d*)?) *$
Divide one variable by another and assign the result to a third variable. Make up the variable names.this = that / the_other^ *.* = .* \/ .* *$
Subtract a variable from a number and assign the result to a second variable. Make up the variable names and the number.result = 1000 - discount^ *.* = [-]?(?:[.]\d+|\d+(?:[.]\d*)?) - .* *$
Multiply a variable by itself and assign the result to the same variable. Make up the variable name.growing_number = growing_number * growing_number^ *(.*) = \1 \* \1 *$
Multiply three numbers and assign the result to a variable. Make up the numbers and the variable name.result = 5 * 6 * 7^ *.* = [-]?(?:[.]\d+|\d+(?:[.]\d*)?) \* [-]?(?:[.]\d+|\d+(?:[.]\d*)?) \* [-]?(?:[.]\d+|\d+(?:[.]\d*)?) *$
In one line of code, display the result of multiplying two variables. Make up the variable names.print(first_number * second_number)^ *print\(.* \* .*\) *$
  1. Assign a number to a variable, and another number to a second variable. Multiply the two, using the variables. Assign the result to a third variable. Display the result using the third variable.
  2. Click the Run button   above your code. If you've coded correctly, the result of the multiplication will display in the right-hand panel. (You can click Instructions at the top of the right-hand panel to see the correct code.)
67462da9d4
  1. In a single line of code, divide one number by another and display the result.
  2. Click the Run button   above your code. If you've coded correctly, the result of the division operation will display in the right-hand panel. (You can click Instructions at the top of the right-hand panel to see the correct code.)
989da53d04