Time needed: 30 minutes
Materials needed:
Setup:
An algorithm is a series of specific instructions that can be applied to many situations. For example, a step-by-step recipe or a set of directions from one place to another are two examples of algorithms you might already use! A function is one of the basic building blocks of a program. It’s a type of instruction that’s similar to a verb: a function does something. Sequence is the order in which the computer performs the steps of the algorithm.
When programmers start working on a new idea, they often sketch out their ideas on paper before they move on to coding their algorithms on a computer. Pseudocode is a way to plan a computer program using human-friendly language. It’s not actual coding, but rather a written description of the key elements of an algorithm or program. It’s used as a quick way of thinking about a program without completely writing it out in code. It saves time and still lets a programmer check that their program will run.
Activity:
For this activity, you’re the programmer! Use code to create an algorithm for a portrait of yourself or someone you admire. Then give the algorithm to someone else, who will use the coded algorithm to draw the portrait.
Note: If you don’t have a partner for the activity, that’s okay! You can test your own algorithm and create a portrait on your own.
First, check out page 1 of the Code a Portrait handout. Make sure you understand what functions are and how to write them with the correct syntax. Look at the examples that work as well as those that don’t!
Then, create a short program in pseudocode with three or more tasks (functions). Together, the functions should make up an algorithm that could tell someone how to draw a smiley face. It may help to ask yourself:
Then, use functions to write pseudocode someone else could follow to draw a portrait of you or someone you admire. The “Portrait Function List” on the Code a Portrait handout has some examples of functions, or you can create your own (as long as they’re in the correct syntax!). Remember to be as specific as possible—once you hand over your algorithm, the “computer” won’t be able to ask questions, and you won’t be able to give any additional instructions!
After you’ve written an algorithm, share your pseudocode with someone else who can play the role of a computer, drawing your portrait by following the instructions. If you don’t have a partner, that’s okay—just follow your own instructions, step by step, to see if you can recreate your portrait.
If the “computer” doesn’t follow the instructions correctly, that’s okay. It might take multiple tries to code the portrait correctly, so mistakes are to be expected. In computer programming, getting code right is a learning process—you can expect to make mistakes, but also know that you can fix them. In fact, sometimes a mistake leads to unexpected results!
After the “computer” is done running the program, look at the final image:
And that’s it! Now that you’ve translated the portrait into code, you could give the program to someone else (or a computer!) to recreate.
This activity reminds us how literal computers are. When creating a portrait, the programmer creates the description, and the computer draws the portrait by following that description. Algorithms are helpful because they’re efficient and general—the functions are simple enough to describe one part of the face and can be reused—think of the draw Eye function.
Troop Leaders: The instructions for all badge steps are available free of charge in your Girl Scout Volunteer Toolkit.
Girl Scout Activity Zone activities have been adapted from existing Girl Scout programming.