Don't like this style? Click here to change it! blue.css
These daily challenges were a little bit beyond you (which is healthy).
For my annuity calculator I did a rough idea like this:
For the interactive Tic-Tac-Toe I borrowed the framework from Corey and added logic:
The basic idea I want to capture is that simple types (int
, str
, float
)
are copied at assignment while complex (AKA non-atomic) types (list
, dict
) are
aliased at assignment. An example:
For aliased data:
That example had a new style of list creation in it. We'll talk about that some more in a minute. For now
notice that .insert(0,0)
impacted both variable names! This is because perfect_squares
is actually just an alias of sums_of_first_k_odds
.
Non-Atomic Task 1: What happens in the next snippet?
Non-Atomic Task 2: What about this one?
Atomic Task 3: What is the value of SimonesDad
at the end of this
snippet?
Local Task 4: Why doesn't the for loop change SimonesDad
in the
following snippet?
Interactive Local 5: Add a command to that for
loop which displays each
letter
after it was upper-cased.
Football Task 6: Fix the following program:
Clone Task 7: What is happening in this alternate universe?
Clone List Task 8: Hand-clone this list: first_4 = [1, 2, 3, 4]
.
Append 5
to your clone. Print first_4
.
Copy Module Task 9: There is an easy way. The Python copy
module.
Observe the following snippet. Use copy.copy
to build me a team of 4 clones and work each clone for
70 hours.
Lost Name Task 10: What goes wrong in the next snippet?
Deep Copy 11: Use the dir(copy)
trick, along with
help(copy.deepcopy)
to fix that situation. Describe to your neighbor the difference between a "copy"
and a "deep copy".
Double Check Task 12: I'm going to give you four functions. Tell me which ones made copies and which ones made aliases.
If there is still time let's go to last Wednesday's Notes and explore the
math
module.
This is adapted from another section of 106's recent exam. How would you do? (Imagine it on paper.) For this daily challenge I want you to work this practice exam and I'll give answers Monday morning.