Replace the basic summation example with a simple simulation of coin-…#637
Replace the basic summation example with a simple simulation of coin-…#637augeas wants to merge 1 commit intoswcarpentry:mainfrom
Conversation
…tosses: 1) It's *entirely* valid for an accumulator to not depend on the loop varaible, c.f. Monte-Carlo integration. 2) We shouldn't solve the problem of `range` starting from zero with spurious additions in a loop, just use `range` properly. 3) A trvial summation over the loop variable should be done with the built-in `sum` function. 4) The later excercise with a cumulative sum is a far better example. Delete the string revering excercise. 1) Strings, and other sequences are more idiomatically reversed with slice operators. 2) The other exercises with string accumulators are much better. On branch loops_grg modified: episodes/12-for-loops.md
🆗 Pre-flight checks passed 😃This pull request has been checked and contains no modified workflow files, spoofing, or invalid commits. It should be safe to Approve and Run the workflows that need maintainer approval. |
|
Thanks for the PR! I like this change personally but would like to gather feedback from the rest of the community as well before moving forward. I believe the original intent of re-implementing I don't think we introduce format strings in the lesson so there should be some explanation of this either now or earlier. Please keep in mind that this is not a foundational computer science course and so statements of Turing-completeness as to whether conditionals should be introduced before loops may not track with the intended audience. There have been multiple suggestions to reorder the episodes and ordering and I don't know that we've ever found true consensus yet... e.g., (etc) |
|
I generally agree on that exercise being not great. I taught it before and left some students puzzled, even though the majority are ok with it. However I would like to point out that your example has a |
Issue #636:Examples / exercises encourage anti-patterns in 12-for-loops.md
Replace the example somewhat heavy-handed summation over a loop variable with a simulation of coin tosses:
rangestarting from zero with spurious additions in a loop, just userangeproperly. 3) A trivial summation over the loop variable should be done with the built-insumfunction.Imports have been introduced previously, so it's probably okay to use random.random()
Other examples in the episode use if statements, but this is just more justification to switch the conditionals and loops episodes; conditionals are more fundamental than loops, if you don't have conditional branches, you're not Turing-Complete, and you don't really have a language.
Delete the string revering exercise.
On branch loops_grg
modified: episodes/12-for-loops.md