Teach Berkeley CS61A To A Middle Schooler : Day 1

My first subject in computer science in college was CS61A from UC Berkeley. The course has evolved over many years.  My favorite CS teacher Paul Hilfinger is now teaching the course in Python.

My goal is to teach my daughter this first year college course to my daughter at 13 years old.   Every journey starts with 1 step.

My lesson plan starts with

  1. Talk to her about the big picture of what a computer is
    1. CPU
    2. Memory
    3. Input/Output
  2. Talk to her about what a computer program is
  3. Do some interactive programming with Python

We installed Sublime 3 Beta editor, fired up Terminal

This is what ended up with my initial lesson plan

  1. Instead of talking about abstract computer, we fired up Activity Monitor on the Mac and look at the Chrome and Chrome helper threads. I told her each tab on Chrome was a thread.  She fired up 10 threads, went to 10 different web searches, saw the growth of processes on Chrome, close them down and saw the threads grow and shrink.  We talked a bit about the memory usage, didn’t get too much into it yet.  Hands on experimentation is definitely much easier to understand the abstract concepts of CPU and memory
  2. Then we started talking about Python and started typing in a simple print statement and then got into defining a function.  She immediately asked me what it really did.  I told her it was a simple way to save from typing something over and over again
    1. She started typing up ‘print “How are you”‘ and then def okay(), def not good(), def awesome(), I let her continue finishing up.  Asked her to type python day1.py.  And we did an interactive troubleshooting of the space for ‘not good()’
    2. We then talked about using input() to get the keyboard input, and because I’m also a Python newbie, I didn’t realize input() in Python 2.x actually evaluated the input.  We decided to go to sleep, but then I looked up raw_input() and when she is already in bed, I told her that raw_input would be what we would use
  3. I certainly learned more about teaching and how kids (at least C.) think and learn. Structure teaching plans are great, but definitely leave room for questions and answers and incremental progression and encourage kids to explore forks of the lesson plan.
  4. What she learned today: using ‘ls’, ‘cd’ in unix.  Using ‘python’ to execute.  using ‘def’.  using ‘if’, ‘elif’

I’m so looking forward to

  1. using chmod() to make the program executable
  2. let her drive the conversation and we learn as we build something she is interested in?
  3. continue with Chapter 1

Regular Expression: Lesson #2

C. is continue to be interested in regular expression. The most fun one seems to be the way to find palindromes

find palindromes with 5 letters


words=/usr/share/dict/words
cat $words | grep '(.)(.)(.)\2\1'

Find any word starting with C, replace with K


cat tck | sed 's/^C/K/'

Find any word ending in Y, replace with I


cat tck | sed 's/Y$/I/

find words with either 1-3 or 5-7


cat no.file | grep '[1-3]|5-7]'

find words with any letter between m and p


cat /usr/share/dict/words | grep '[m-p]'

bash and unix commands: lesson #2

1) counting words


cat /usr/share/dict/words | wc -l

2) counting characters


cat /usr/share/dict/words | wc -c

 
3) replacing the ‘enter’ or ‘newline’ with comma


cat /usr/share/dict/words | tail -7 | tr '\n' ','
zymotoxic,zymurgy,Zyrenian,Zyrian,Zyryan,zythem,Zythia,

4) replacing more than a single character


cat /usr/share/dict/words | tail -7 | sed 's/Zy/Baaa/'
zymotoxic,zymurgy,Zyrenian,Zyrian,Zyryan,zythem,Zythia,

Fun infinite loops: random number guessing: bash #3

An actual game using Terminal on the Mac is something with guessing numbers

Open the Terminal.App from your Mac by holding down command space and typing Terminal


RANDOM=$$
while true
do

echo "can you guess a number between 1 and 10 : "
read
echo The number is :
echo `expr $RANDOM % 9 + 1`
echo

done

can you guess a number between 1 and 10 :
3
The number is :
5

can you guess a number between 1 and 10 :
4
The number is :
5

can you guess a number between 1 and 10 :
9
The number is :
4

can you guess a number between 1 and 10 :
The number is :
3

Control-C to tell the computer to stop, remember the computer is not very smart like humans

See all posts about Fun infinite loops

Fun infinite loops : bash #2

A second fun loop with Terminal on the Mac is something with time

Open the Terminal.App from your Mac by holding down command space and typing Terminal

while true
do
date
date +%T
sleep 1
done

Thu Nov 7 07:38:50 PST 2013
07:38:50
Thu Nov 7 07:38:51 PST 2013
07:38:51
Thu Nov 7 07:38:52 PST 2013
07:38:52
Thu Nov 7 07:38:53 PST 2013
07:38:53

Control-C to tell the computer to stop, remember the computer is not very smart like humans

See all posts about Fun infinite loops

Fun infinite loops: bash #1

C. somehow got interested again in programming and she opened the Terminal App from her Mac and typed


echo why doesn't this work
quote>
quote>
quote>
quote>

I told her the single quote character is a special character that the not so smart computer need the human to escape it

Control-C would tell the computer to abort whatever it is doing

echo "why doesn't this work

Then she asked how do we do that infinite loop

while true
do
echo hey you c8
sleep 1
done
hey you c8
hey you c8
hey you c8
hey you c8
hey you c8
hey you c8
hey you c8
hey you c8
hey you c8

Fun!