swcarpentry / python-novice-gapminder

Plotting and Programming in Python
http://swcarpentry.github.io/python-novice-gapminder/
Other
163 stars 427 forks source link

In 16-writing-functions, print_date example needs revising #538

Closed ognancy4life closed 3 years ago

ognancy4life commented 3 years ago

In lesson 16: Writing Functions, there is a question regarding "Order of Operations" using the print_date function. This is a good question, but because print_date has already been defined earlier in the lesson, the students will not get the desired error. I recommend using a different example function here to teach order of operations. Thank you!

alee commented 3 years ago

Excellent point, thank you for raising it!

http://swcarpentry.github.io/python-novice-gapminder/16-writing-functions/index.html#order-of-operations

AlexT97 commented 3 years ago

One suggestion with Order of Operations, I think it might be clearer for students looking through this to have multiple examples to work with. The print_date is probably okay to work with but I would recommend something a bit shorter to go alongside. One thing that might be useful would be to have another full example of a function definition, like @ognancy4life suggested, but using mathematical expressions. This way, it's short, with hopefully pretty transparent functionality and that way, it doesn't really get in the way of the bigger issue of order of operations in a Python script. In addition, an example like this might make explaining exactly what went wrong and why a lot easier. That could even be a good lead-in to the print_date order of operations example. A good example for a simpler order of operations example might be something like this:

basic_math(1,2,3) def basic_math(x, y, z): return (x + (y * z))

perlman commented 3 years ago

My PR (#546) was an effort to change this with the minimal edits.

The example @AlexT97 provides would certainly work, and might be superior in that there would be less to type in if a student tries to do so. I guess the question is which additional concepts would be less confusing: using parentheses to order mathematical operations, or string building?

I don't know. :)