python-novice-gapminder icon indicating copy to clipboard operation
python-novice-gapminder copied to clipboard

"Variables and assignments" - lesson and exercises improvements

Open mforneris opened this issue 6 years ago • 3 comments

General feedback

I had the chance to teach Episodes 1 to 7 to a class of researchers in molecular biology with little experience in programming. The class really liked the course, the pacing and the amount of material that was covered. It was also very nice to go into practical applications early on to keep the students engaged.

Course timing

It actually took us 2 days (from 9:30 to 5) to cover the whole material, only adding an episode about numpy. I think the timing reported within the episodes are too short for a novice audience (especially if instructors take some time to correct a handful of exercises after giving some time to solve them).

Variables and assignments Lesson

Comments should be introduced here

The concept of comments within python scripts has not been introduced in this episode but it will be only in Episode 4. I suggest to introduce it here since it is widely used in the exercises and people had a hard time interpreting it.

Variables and assignments Exercises

Students found some of the exercises in "Variables and assignments" (http://swcarpentry.github.io/python-novice-gapminder/02-variables/) challenging to understand. I'll summarize here the comments from the audience and some suggestions on how to improve the exercises.

Swapping Values

The audience was just introduced with the concept that code gets executed line by line. In addition, comments are necessary to understand what is written here. I would suggest restructuring the exercise in this way:

# Consider the code below. What is the value of each variable after each line of code gets executed? Fill in the table with the value of the variables in this program after each statement is executed x = 1.0
y = 3.0
swap = x
x = y
y = swap
# Line # Value of x # Value of y # Value of swap # Line 1 # # # # # Line 2 # # # # # Line 3 # # # # # Line 4 # # # # # Line 5 # # # #

The students also found a bit challenging to understand the meaning of the exercise (swapping value between variables) at this stage and as a first exercise in the course. I think it would be nice to move it to the end as the last exercise or before "Slicing concepts" since it wraps up well many concepts introduced in this lesson.

Slicing concepts

This exercise was again a bit hard to understand by the students. I would reformulate the question so students should write some code instead of reasoning on what is written there. Many students were asking what is "low" or "high" or if they were variables. For example, I would rephrase the exercise in this way:

# Given the string: full_name = "James Bond" # What would these lines return? # 1. full_name[7:10] # 2. full_name[6:] # 3. full_name[:4 # 4. full_name[:] # 5. full_name[2:-1] # 6. What happens when you choose a high value which is out of range? (i.e., full_name[0:15])

Conclusions

If you think the changes to the exercises could help, I would be happy to submit some pull requests to implement them.

mforneris avatar Jan 13 '20 18:01 mforneris

Thank you for the very detailed feedback @mforneris ! PRs for all of the issues you raised would be most welcome, and we could further refine the enhancements to the exercises you propose and update the listed timings in those PRs. Other would-be instructors have contacted me about actual times for running through this lesson with different audiences and your notes here would be very helpful for them or to aggregate with other feedback we've received into this lesson's instructors guide.

For the slicing example I agree that low and high could cause confusion especially since it's not a given that the first argument will be less than the second argument as your examples show. I believe the convention and Python docs typically refer to the slice arguments as start, stop, step and I'd be all for changing those examples to adopt that nomenclature.

alee avatar Jan 13 '20 23:01 alee

I still think it would be good to have an example for going over the range for string. And Also what chars or names are invalid and create errors (like '.' '*' start with numbers or reserved keys)

voghoei avatar Jun 24 '21 15:06 voghoei

This is my first comment, please forgive me if I am doing this wrong. I agree that adding a blurb about commenting to either the end of the first lesson (doesn't seem to be a good fit) or the beginning of the second lesson is a good idea. Otherwise students will be put in a situation where the teacher says look at this comment, which we'll discuss later. Maybe a complete copy of the comments section from lesson 4?

I also notice that the exercise for Slicing concepts is uses low/high but the earlier convention is start/stop. I am not sure if that was intentional but I might be confused as a student seeing that difference.

Another alternative slicing exercise that could be applicable to a large audience since a lot of us have to get data out of the middle of a string is below. it might be a bit much to chew on. Number 6 is to cover that you can use two negative numbers when slicing.

Slicing practice

given the string: unique_identifier = "2021-07-02_ABC123"

  1. What does unique_identifier[:] return?
  2. What does unique_identifier[:10] return?
  3. What does unique_identifier[11:] return?
  4. What does unique_identifier[8:10] return?
  5. What does unique_identifier[:-6] return?
  6. What does unique_identifier[-6:-3] return?
  7. If the unique_identifier above is in format YYYY-MM-DD_identifier, what is the slice[:] for extracting MM without using negative numbers?

Solutions

  1. unique_identifier[:] returns the full string "2021-07-02_ABC123"
  2. unique_identifier[:10] returns "2021-07-02"
  3. unique_identifier[11:] returns "ABC123"
  4. unique_identifier[8:10] returns "02"
  5. unique_identifier[:-6] returns "2021-07-02_"
  6. unique_identifier[-6:-3] returns "ABC"
  7. The slice for getting MM is unique_identifier[5:7]

brianmatthewthomas avatar Jul 02 '21 19:07 brianmatthewthomas