I also do a candy loop.

I use the random.choice() function to select a color from a list and a loop
to fill it a 'bowl' (another list) with those random colors.  From there
you can loop through each candy and count it, pop it, etc.  Also a great
way to introduce for loops under the guise of analysis.

I made a Trinket with a demo for a non-SWC workshop I taught:
https://trinket.io/python/7244ee15f4

Elizabeth


On Thu, Dec 3, 2015 at 9:17 AM, Shauna Gordon-McKeon <[email protected]>
wrote:

> I've taught basic programming to kids and in these cases it's always nice
> to have a metaphor with candy.  So: Halloween.
>
> def Halloween:
>     plan costume
>     get in costume
>     go outside
>     for house on street:
>        walk to house
>        ring doorbell
>        get candy
>        say thank you
>
> If you've already taught if statements, you can do if trick: run away
> screaming, else: take candy
>
> You can also add a candy_count variable to the loop.
>
> Might be too silly for adults, but thought I'd share it anyway.
>
>
>
> On Thu, Dec 3, 2015 at 8:25 AM, Steve Haddock <[email protected]> wrote:
>
>> I use a shopping basket and then `for item in basket`. The fact that the
>> item could be a single thing or a carton of eggs (=list), which could also
>> be looped through, helps.
>> I think the point about not using `egg` as the variable name is extremely
>> import.  If you say `for line in myfile` they think `line` is a magic word
>> that grabs a line and `word` or `letter` would act differently.
>> The main conceptual hang up seems to be how the variable gets reassigned
>> each time.
>> It is also not "proper convention" and freaks out CS people, but I like
>> to capitalize the variable names, so it is easier to distinguish special
>> Python words from arbitrary names.
>> -Steve
>> ----- q•b -----
>>
>>
>> > On Dec 3, 2015, at 01:24, Karin Lagesen <[email protected]>
>> wrote:
>> >
>> > The more I teach, the more I realize that I am not really able to
>> convey what a for loop does to everybody. Do any of you have a metaphor or
>> something that you use for teaching it? I explain about variables and
>> collections, and the body of the loop, and I show examples, but I am still
>> not able to get through all the time.
>> >
>> > Karin
>> >
>> > _______________________________________________
>> > Discuss mailing list
>> > [email protected]
>> >
>> http://lists.software-carpentry.org/mailman/listinfo/discuss_lists.software-carpentry.org
>>
>> _______________________________________________
>> Discuss mailing list
>> [email protected]
>>
>> http://lists.software-carpentry.org/mailman/listinfo/discuss_lists.software-carpentry.org
>>
>
>
> _______________________________________________
> Discuss mailing list
> [email protected]
>
> http://lists.software-carpentry.org/mailman/listinfo/discuss_lists.software-carpentry.org
>
_______________________________________________
Discuss mailing list
[email protected]
http://lists.software-carpentry.org/mailman/listinfo/discuss_lists.software-carpentry.org

Reply via email to