In the near future, I'm going to be doing a series of short workshops for teens aged 13-17, who may not have any programming experience at all, showing them the basics of programming and webapps. The workshops are short, so it really has to stick to the absolute basics. The apps will be written in Python, for App Engine.
Edit: I guess I wasn't very clear about the scope of this. The workshops are very short indeed - no more than about 20 minutes - and as such, it's impractical to start from scratch, or teach them programming in general. The goal here is to start off with a pre-written webapp, written in such a way as to make it easy to make trivial changes to the text of individual steps, and to make slightly less trivial changes to the code for more ambitious students. Then, we spend the time with them demonstrating how to customize it for their own quiz, and deploy it, and give them the code to take home. Hopefully some of them will be interested and pursue it in their own time.
The app we've chosen to implement is a very basic "what [x] are you" quiz. We're using this for several reasons:
- Everyone is familiar with them - they're quite popular, especially on social networks. People generally understand the basic idea of how these things work behind the scenes (I think).
- They're very simple to program. Complex flow control, loops, array and dict access, etc, can all be kept to a minimum.
- Even without any programming background, students can easily modify the text of the questions, answers, scores, and outcomes, and get a real sense of achievement. With a little programming knowledge, they can make more substantial changes like adding or removing questions, and changing the scoring criteria.
- Once they've created an app, they can show it off to their friends and have them try it out.
The basic flow of the app is that there are a series of question pages, each of which has multiple-choice answers. Each answer modifies the value of one or more internal scores. At the end of the quiz, the outcome corresponding to the internal score with the highest value is displayed. For example, in the "what dwarf are you" quiz, answering the question "What would be the perfect gift for a girl?" with "a shy smile" increases the score for "bashful" and decreases the score for "grumpy".
Now that I'm actually writing the template app, I'm trying to figure out the best way to represent it. How would you suggest writing an app like this for an audience who may have no programming experience at all? As I see it, I have several options:
Procedural with magic: Define a base handler for the app that does things I don't expect the students to understand (getting request parameters, converting strings to ints, assembling redirect URLs, etcetera), and have a handler per question that extends the base handler with specific logic. This makes the code as simple as possible, so they can understand the exposed bits more easily, but hides a lot of detail, so it'll make understanding the whole thing a bit more complicated. Handlers would look something like this:
class Question1Handler(webapp.RequestHandler):
def get(self):
"""Show the page for this question."""
self.ShowQuestion(
"Question Title",
"Answer 1",
"Answer 2",
"Answer 3",
"Answer 4")
def HandleAnswer(self, answer, a, b, c, d):
"""Handle the answer to this question."""
if answer == "1":
self.NextQuestion(2, a + 1, b, c, d)
elif answer == "2":
self.NextQuestion(2, a, b + 1, c, d)
elif answer == "3":
self.NextQuestion(2, a, b, c + 1, d)
elif answer == "4":
self.NextQuestion(2, a, b, c, d + 1)
Procedural with less magic: Like the above, but with basic use of dicts to make it easier to change the number of outcomes.
Data-driven with external resources: Load the questions, answers, scoring criteria, and outcomes from a couple of CSV files. This makes it really easy for students to change the questionnaire, but much more difficult for them to understand and make changes to the logic.
Data-driven with data structures: Like above, but using Python data structures embedded in the code. Eg:
questions = [
('Question 1', ('Answer 1', {'a': 2, 'b': -3}), ('Answer 2', {'b': 1})),
# ...
]
outcomes = [
'Most points for answer a',
'Most points for answer b',
# ...
]
This option should make the logic a bit simpler, and it's still easy to modify, but it still requires a lot more knowledge for them to understand the logic.
So what's the best way to write this? Do you have suggestions other than those above?