Another worked example

Here's how I'd do an exercise. Particularly useful for preparing for exams.

Here's the exercise.

- - CUT SCREEN HERE - -

Cthuhlu plans to knit leg warmers for his goat friends. Write a program to work out how much yarn it will need. Yarn is measured in geins. Like a skein, but for goats.

There are three sizes of warmers: small, medium, and large. Here are the number of geins.

Goat size Geins needed
Small 2
Medium 3.4
Large 5.8

Of course, each goat will need four leg warmers.

Here's what the worksheet should look like to start:

Starting worksheet

Here's some output:

Output

And some more:

More output

- - CUT SCREEN HERE - -

STOP! Before watching the video, try the exercise yourself.

You tried it?

You did, right?

OK, here's how I'd do it.