Climb the Ladder!#
Our class moves quickly! Sometimes, it feels like we make leaps in logic that are a bit too big. Learn Python slowly, by doing many, many examples. Problems in this notebook start out easy and progressively get harder, so that the next rung of the Python ladder is always within reach.
Section I: Numbers, variables, and math.#
What is 123456789 times 987654321?
Create a variable called
massthat is equal to 100.
Create a variable called
velocitythat is equal to 5.
In physics, the momentum an object is exerting is equal to its mass times its velocity. That is, \(p = mv\). Use the variables you defined above to compute this object’s momentum.
The kinetic energy of an object is half its mass times the square of its velocity. That is, \(K = \frac{1}{2}mv^2\). Compute the kinetic energy for this object using the variables you’ve already created.
How much icing do you need?#
In the next few exercises, our goal will be to figure out how much icing we will need to perfectly cover a giant doughnut. The doughnut features a hole (unfortunately no jelly filling), and a few large sprinkles. We only need to find the area of the red region in this shape.

Create a variable called
pithat is equal to 3.141
The radius of the largest circle is 13.425. The radius of the smaller circle is 4.792. The sprinkles are right triangles with side length 3.28. Create the variables
R,r, andsthat represent these values.
Find the area of the larger circle (the whole doughnut, including the hole). Call this variable
area_big_circle.
Hint: The area of a circle with radius \(r\) is \(A = \pi r^2\).
Find the area of the smaller circle (the hole). Call this variable
area_small_circle.
Find the area of one triangle (a sprinkle), where each sprinkle has a base and height of length
s. Call this variablearea_sprinkle.
Hint: The area of a triangle with base \(b\) and height \(h\) is \(A = \frac{1}{2}bh\).
Using the three values you calculated above, find the area of the shaded region (i.e., how much icing will you need?). Save the result in a variable called
area_donut.
Part II: Strings#
Create a variable called
namethat is equal to your name.
By adding strings together, introduce yourself in a string. For example
"Hello, my name is Tim!". You may use f-strings if you know what they are and prefer to use them.
Define the string
factto be"Python programming is fun."
Index
factin order to get the “o” in “Python”.
Index
factin order to get the “u” in “fun” using a negative index.
Slice
factin order to get the word “programming”.
Uppercase
fact.
Replace the period at the end of
factwith an exclamation point.
Use
.split()to get the second word of this string. Was this easier than one of the problems above?
Reverse
fact.
Does
factcontain the lettery? To find this answer, use theinkeyword.
How many
os doesfacthave?
Replace all the
os infactwith an underscore (do not redefinefact).
Part III: Lists#
Create a list
friendsof your three best friends,"Alice","Bob", and"Charlie".
Find the length of
friends.
Add your new friend
"Debbie"to your list offriends.
Charlie has no-showed to your piano recital. Remove him from your
friends.
Using the
.join()method, joinfriendsto look like this exactly:"Alice & Bob & Debbie"
What is the length of
[]? What about[[]]? Why?
For the next few problems, we’ll use this list:
nested_deep = [1, [2, 3], 4, [5, [6, 7, [8]]]]
What is the length of
nested_deep?
Index
nested_deepto get the 5.
Index
nested_deepto get the 8.
Hint: If your answer looks like
[8], that’s not the correct answer!