This week I taught a class called Moderately Advanced Projects (Mostly Python), for four of my students, who are going into grades 7–10. This group doesn’t appear on my Meetup.com calendar because it was privately formed by the parents and me.

Customization

This class, like most of my others, was highly customized for the interest and abilities of the students. Two of the students were planning to use the C programming language for robotics, and the other two students were interested in C as well, so we spent some time with that language.

Monday

Python

We started with a warmup Python project, counting the occurrences of letters in a sentence, i.e., how many ‘a’s, ‘b’s, etc., first without using a dictionary, and later with one.

sentence = 'It was the best of times, it was the worst of times.'

counts = {}

for letter in sentence:
    count = counts.get(letter, 0)
    counts[letter] = count + 1

print(counts)

Here’s the output: {'e': 5, 'o': 3, 'i': 3, 'b': 1, 'h': 2, 'r': 1, 't': 8, ',': 1, '.': 1, 's': 6, 'f': 2, 'w': 3, ' ': 11, 'I': 1, 'm': 2, 'a': 2}

Scala with Kojo

Then we played around with Kojo, eventually ending up with patterns like the ones from this Facebook post about my Scala class:

Tuesday

Python Chat Server

Expanding on some work some of these students had done before, we wrote a simple chat server. It started something like this:

app = Flask(__name__)
messages = []

@app.route('/post/<who>/<message>')
def post_message(who, message):
    messages.append((time(), request.remote_addr, who, message))
    print(messages)
    return "Message saved.\n" + str(messages), 200, PLAIN_HEADER

app.run(host='localhost', debug=True, threaded=True)

C Language

In keeping with tradition, we wrote a Hello, World program in C.

#include <stdio.h>

int main(int argc, const char * argv[]) {
    printf("Hello, World!\n");
}

Then we learned about functions, and getting input from the console, and wrote a temperature scale conversion program.

Wednesday

Review

These were our review questions:

  • What is an apothem, and how did I use it to place the multihexahexagons?
  • How does Atom recognize the language you are programming in, so it can color-code?
  • How can you style a table with Twitter Bootstrap?
  • What else can you do with Twitter Bootstrap?
  • What are some differences between any of C, Python, and Scala?
  • What does gcc do?
  • How do you make a function in the languages you know?
  • In C, how can you get input of various types from stdin (the console)?
  • What is CSS?
  • What HTML elements do you know?
  • What is IP? UDP? TCP?
  • What does Flask do?
  • What does @app.route do?
  • What does requests do?
  • What is Django?

Screen Scraping

We learned the basics of pulling information from a web page using Python and Beautiful Soup.

Brute Force Password Cracking

Important note: nothing we did here promoted any unethical activity.

One of the students wanted to try brute force cracking MD5-hashed secret messages. We worked on this for awhile, and later I wrote an implementation.