Closed hfboyce closed 4 years ago
Posting what I've done so far (Ex1) in case you want to review it before today's meeting. I'll try not to forget the rest this time!
def squares_a_list(numerical_list, a_new_variable):
Cold
vs. cold
;; return should be in code font;; copy
before?Error
as an option here. How about Both and Neither instead? f
that calls a function g
, then g
could mess with a variable from f
. It's a side effect, but the variable is not a global variable. It's just a variable from outside the scope of g
. Could we maybe tighten up the wording of the question?___
exponent_a_list(numbers, 5)
or exponent_a_list(numbers, exponent=5)
5
is the list and [2, 3, 5]
is the exponent.";; ok so this is again teaching 2 things at the same time; as mentioned above, we need to first teach exponent_a_list(numbers, exponent=5)
, then talk about how it's OK to call exponent_a_list(numerical_list=numbers, exponent=5)
and then talk about the ordering issue that we see here.Here is 9-16, I'll have to do the rest tomorrow (or Thursday at the latest!):
def
and documents the function's purpose and usage.;; period after "things"___
if
statements we're using them with. Let's just delete the "if the condition results in a True value.";; have they seen isinstance
before? if type(numerical_list) != list
instead, so they didn't have to learn something new here. Let's discuss at the next meeting. ;; int
should be list
;; change "If the condition is True, what the problem is" to "raise an Exception (throw an error) with this message";; no space in "straight forward"if
. all
.Exception
is a generic, catch-all exception type. There are also more more specific types of exceptions; for example, you may have encountered ValueError
or a TypeError
at some point." there's a confusion here between what "an exception" is. Is this an exception? Exception("You are not using a list for the numerical_list input.")
I guess so. But in my head I immediately think of different types of exceptions if someone talks about different exceptions. So maybe we shouldn't muddy the waters by saying that Exception("A")
and Exception("B")
are two different exceptions.assert
statements." assert
statements are just one way of implementing this, but the big idea is the unit tests. print('Will this line execute?')
, or put it in later . At first let's not have any distractions from the assert." 1 is not equal to 2."
;; so what I'd do is make a new slide withassert 1 == 1 , "1 is not equal to 1." (note your message needs to be changed here)
print('Will this line execute?')
and
assert 1 == 2 , "1 is not equal to 2."
print('Will this line execute?')
assert
). It feels a bit muddled right now. Something earlier on would be helpful, like on the first slide, saying we'll first talk about assert
and then how we use them in unit tests. Remember, we have the table of contents in our head, and where we are in it, but the learner doesn't have that.isinstance
if that's what we're teachingbad_function
is defined, need some short text explaining what's wrong with it;; this is a pretty contrived example, let's think of something more realistic. A slightly more plausible one (though still not great) could be:def bad_function(numerical_list, exponent=2):
new_exponent_list = [numerical_list[0] ** exponent] # seed list with first element
for number in numerical_list[1:]:
new_exponent_list.append(number ** exponent)
return new_exponent_list
which will fail for an empty list.
return list()
be better? I would prefer something that runs.assert acronym_it("Hard work pays off") == 'HWPO'
assert acronym_it("Hard work pays off") == 'Hwpo'
assert acronym_it("Hard work pays off") == 'H'
assert acronym_it("Hard work pays off") == str
and then we don't need the ???
at all. Then for the answers you'll just need to repeat the 4 lines like you did for 18.2. And for 18.2 I'd also show the 4 lines.
assert
, which may confuse them when they get heremultiply(["a", 5]) == "aaaaa"
, which passes, but doesn't really test what the function is supposed to be doing? type(x) ==
or isinstance
. I wonder if maybe type(x) ==
is better. but my problem is an ego/vanity problem, that I don't want to look like I don't know. In such cases I usually pick the way that's better for students but add a little disclaimer like "See isinstance
for a more advanced approach."type(x) ==
here as well.exponent_a_list_of_lists
and show why that is weird. Or could we go with the example from DSCI 511 instead?In particular "what happens if we want to do other calculations with the dataframe?" is a bit vague.
count_the_sevens
;; answer 4 is incorrect, here's the message:Incorrect. Perfect! Let’s make the count variable (in this case the 7) an input argument.
😂
wage_increase
and in general let's set a good example by providing docstrings from now on;; I didn't really know what I was supposed to do here, let's make the instruction more explicit. How about we give them the stub and the docstring for the new function? or at least tell them what design practices, I guess just the loop one and the hard-coding one, right?I would also mention that it also uses the local copy if it comes in as an argument def squares_a_list(numerical_list, a_new_variable)
I'm not sure what you mean, like if
def squares_a_list(numerical_list):
a_new_variable = "Ta-Da!"
print( a_new_variable)
new_squared_list = list()
for number in numerical_list:
new_squared_list.append(number ** 2)
return new_squared_list
and we said numerical_list = [54, 25, 3]
from within the function?
1.10: These are very dangerous waters. Also this is technically true, it's also misleading. Because if global_var is a list then you can modify its elements inside of the function, even if you can't modify "the list itself". I think we might be better off saying the situation is complicated and we recommend not trying to do this. Update: oh, now I look at 1.11. Hah. Ok soo... I think we'd better drop 1.10 and go straight to 1.11. I think 1.10 just muddies the waters. Then we'd also need to remove "Since we did not use the assignment operator, we were able to make a modification to the global variable. " in 1.12. Or, if we really want 1.10, I'd at least move it to the end or something.
I just removed 1.10 altogether. That work?
1.16: you didn't show the calling of the function - should show it!
I do show it? It just doesn't produce an output since the function has no return.
1.17: not sure if this is coming later, but we should say that if you have side effects, they need to be clearly documented in the docstring (have we taught docstrings yet? if not, do we want to reorder?)
We tackle docstrings 2 slide decks from now. Should I come back to it in that section or do we reorder?
2.2: I got this wrong also. But are you sure?? I think it might be better to remove this, per my comments about 1.10 above.
I use real code for all these and the answer is what I implied as correct. I still am not 100% sure why we would cut in this case because I'm just asking for the output of the function essentially which uses the local variable.
4: consider splitting this into 2 code blocks, so they can more easily see the output of the provided code- not possible currently because of all the ___
Commented this out instead? Does that work?
I'm having a problem with docker. For ex 4, I press run code and get an error. Then I deleted all the ___ and pressed "run code" again but nothing happens! Does this happen to you as well??
Can you try it again now that I've commented things out? I can explain the issue at our meeting.
9.9: I'm not sure, pls check if the default part needs to be in more of a standardized format in the numpy style, e.g. "default = 2" or "default : 2"
This is now the format as recommended by the documentation
we should clarify that part of the use is people who are directly looking at the code, not just this ? type thing
? Je ne comprend pas
13.5: Argh, I know I keep contradicting myself, but I wonder if we should have just gone with if type(numerical_list) != list instead, so they didn't have to learn something new here. Let's discuss at the next meeting. ;;
DISCUSS
there's a confusion here between what "an exception" is. Is this an exception? Exception("You are not using a list for the numerical_list input.") I guess so. But in my head I immediately think of different types of exceptions if someone talks about different exceptions. So maybe we shouldn't muddy the waters by saying that Exception("A") and Exception("B") are two different exceptions.
This needs elaboration please
17.6: "It’s also good to do multiple test to for different list sizes" (multiple grammar issues). ;; we should be consistent here and use isinstance if that's what we're teaching
I initially included isinstance
since it's the easiest way to test if an object is of type pd.DataFrame
. Instead I removed it and added a hint in the assignment to use that function. Is this ok?
17.11: I'm a bit confused about this, because this code does not run. Would return list() be better? I would prefer something that runs.
What do you mean? which code?
?
Is this ordering taken from somewhere?
Your lecture actually 😂 actually. See here
3: have they heard the term pseudo-code before?
No but I explain it in this slide. Is that not enough?
18.1: put "not" in bold/italics like 18.2
Are you looking at the same question as me?
19: missing a space in the last choice;; also, I don't know, this one is a bit subjective. There might be a purpose to those tests. for bad tests, what if you add a docstring to the function that shows the inputs are supposed to be numbers, and then have a silly test like multiply(["a", 5]) == "aaaaa", which passes, but doesn't really test what the function is supposed to be doing?
Remove then?
21: do we really need the messages here?;; again, we should decide if we're doing type(x) == or isinstance. I wonder if maybe type(x) == is better. but my problem is an ego/vanity problem, that I don't want to look like I don't know. In such cases I usually pick the way that's better for students but add a little disclaimer like "See isinstance for a more advanced approach."
Adding messages just so they have familiarity with it and removed isinstance
Or could we go with the example from DSCI 511 instead?
I've been using DSCI 511 as a resource. Which example are you referring to?
22.9: needs a bit of work. let's be more specific about the pain points:
Let's talk about this a bit more.
1) argument to function with same variable ( uses the one with the argument)
2) remove 1.10
3) 1.16 show function -> call it on same slide when call 1.17 show unheated function, calling function and cereal all on same slide and function still worked (unheated cereal)
If you do have side effects you document them HERE is where we mention side effects (in docstring)
exercise 4) pass in weight_lb and remove return statement. change wording to just global and local environment
change "loading to blank"
sentence for reading document
isinstance add note in content-> there is a more robust way using isinstance (see here ->) we don't want to over complicate this In the interest of avoiding new syntax (this is a simple way of doing this, for a more robust approach see link)
17.15 return empty list here
peusdo code (say in the comments )
18.2 BOLD not
@mgelbart Here is the first draft of Module 6! it is available here. There is also assignment 6 that is done too ( here).
I plan to organize and start content for Module 7 Monday and Tuesday!