swcarpentry / python-novice-inflammation

Programming with Python
http://swcarpentry.github.io/python-novice-inflammation/
Other
300 stars 778 forks source link

Programming with Python Episode 3 Example Suggestion #762

Open CRWayman opened 4 years ago

CRWayman commented 4 years ago

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

ldko commented 4 years ago

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!

CRWayman commented 4 years ago

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. :)

maxim-belkin commented 4 years ago

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.