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

Programming with Python Episode 3 Example Suggestion

Open CRWayman opened this issue 4 years ago • 3 comments

In Episode 3 of Programming with Python, there is an exercise which shows that as a for loop iterates through a string of the five vowels, a variable is updated. I have found that this exercise skips a few logical steps, and that users who are new to Python struggle to understand the outcome of this loop.

I recommend augmenting the loop slightly so that instead of

length = 0
for vowel in 'aeiou':
    length = length + 1
print('There are', length, 'vowels')

You would have

length = 0
for vowel in 'aeiou':
    length = length + 1
    print(length)
    print(vowel)
print('There are', length, 'vowels')

This would provide a sort of hard-coded enumeration example that could show learners how the steps occur on each iteration, and really drive home the idea that loops are moving through each character in a string. It will only help learners reinforce ideas that are taught earlier in the lesson through repetition.

http://swcarpentry.github.io/python-novice-inflammation/03-loop/index.html

CRWayman avatar Nov 25 '19 19:11 CRWayman

Hi @CRWayman, I think your suggestion in this issue would be a good addition. Not only does it help clarify what is happening, but it also shows that you can execute multiple lines of code within the for loop, which I don't think is shown in this episode's content. Do you have any thoughts about using print(length, vowel) to show the output of each iteration on one line rather than doing the two print statements individually? We welcome a PR to address this issue. Thank you!

ldko avatar Jan 10 '20 23:01 ldko

Hello! I agree that the combination would be better as a single line print statement, I also think it's a good way to reiterate to beginners that you can print multiple variables in a print statement. I'm not sure how to do this as a pull request, are there instructions on how to do this? I wouldn't want to mess anything up. :)

CRWayman avatar Jan 16 '20 16:01 CRWayman

You can make changes using the GitHub's web interface:

  1. Navigate to the _episodes folder: https://github.com/swcarpentry/python-novice-inflammation/tree/gh-pages/_episodes

  2. Click on the episode you'd like to change: https://github.com/swcarpentry/python-novice-inflammation/blob/gh-pages/_episodes/03-matplotlib.md

  3. Click on the Edit (pencil) icon Screen Shot 2020-01-16 at 11 05 04

  4. Change the file as you feel fit.

  5. Scroll to the bottom of the page and: Screen Shot 2020-01-16 at 11 09 13

  • Add a title for your changes
  • (Optional) explain what you did and why in detail
  • (Important) Select "Create a new branch for this commit and start a pull request"
  • Choose a name for the created Git branch. Remember it as you might need it in the future if maintainers (us) ask you to make any changes further down the road.

maxim-belkin avatar Jan 16 '20 17:01 maxim-belkin