python-novice-inflammation
python-novice-inflammation copied to clipboard
Programming with Python Episode 3 Example Suggestion
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
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!
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. :)
You can make changes using the GitHub's web interface:
-
Navigate to the _episodes folder: https://github.com/swcarpentry/python-novice-inflammation/tree/gh-pages/_episodes
-
Click on the episode you'd like to change: https://github.com/swcarpentry/python-novice-inflammation/blob/gh-pages/_episodes/03-matplotlib.md
-
Click on the Edit (pencil) icon
-
Change the file as you feel fit.
-
Scroll to the bottom of the page and:
- 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.