Beginner Computer Programming for Women

Beginner’s Approach to Computer Programming for Women

Hello, and welcome to the course page for the Beginner’s Computer Programming course, focusing on Python. This course will be using the EarSketch software to teach Python using music composition and remixing. If you have no prior experience in programming or music, don’t worry. Both will be helpful, but are not necessary. I will be updating this site with content and resources for each day’s lesson, so check back regularly to review what we did each day, or look ahead for the next day.


If you have any questions, please feel free to email me at


Thank you,

Michael Madaio



Useful Links:



Day 7 (7/24/14)


This is the final day! 🙁


Today, you will create your final song, using everything you have learned at this point. When you are finished, you can export it to a .Wav file, and email it to yourself to keep forever!


Here are some guidelines for what to include in the song:

  • At least 6 different instrument variables
  • At least 3 or 4 different “for loops”
  • Some of those might have multiple fitMedia functions inside them
  • These should be taking place at different ranges.
  • Try to use at least 2 “if conditions” (ie: if measure > 17:)
  • You can use > (“greater than”), < (“less than”), >= (“greater than or equal to”), <= (“less than or equal to”), or == (“equals”).
  • Remember you can use an “else” after the “if”


for measure in range(1,33):

if measure <=16:

fitMedia(piano, 1, measure, measure+1)


fitMedia(organ, 2, measure, measure+1)


When you are finished, be sure to save to the cloud AND click on “Save file as a WAV on your computer.” You can then email that file to yourself to “take home”.




At 5:30 today, click this link to take a final course survey, and we will pass out our course certificates when you finish.



Great job these past 3 weeks!




Day 6 (7/22/14)


Welcome to the start of our final week! Today and Thursday are our last two classes.



Open up your songs from last Thursday, and make sure you have at least 4 instrument variables assigned to sound file constants.

Also, make sure you used the “for loop” to call a function multiple times in a range. Remember the syntax there:


for measure in range(1,33):

fitMedia(drums, 1, measure, measure+1)       # Where “measure” is a variable that runs through all of the values of the range, changing each time it iterates through the loop.






We will learn what we call “conditional” logic. That is, we will run a check to see if a certain condition has been met. If so, we will do something (run a function). If we want, we can add an “else” to have it do… something else (another function), if the condition has NOT been met.


if measure < 17:

fitMedia(piano, 2, measure, measure + 1)


fitMedia(strings, 2, measure, measure + 1)



You might notice that this uses the same variable “measure” as we used in our for loop. That means that this if statement needs to be “inside” of the for loop. That is:



for measure in range(1,33):

if measure < 17:

fitMedia(piano, 2, measure, measure + 1)


fitMedia(strings, 2, measure, measure + 1)








Day 5 (7/17/14)


Today we will be learning how to use a “for loop” to make creating longer songs a lot easier.



Open up the Code Editor linked to above, and open up your songs from Tuesday.




  • Create 4 different instrument variables to use in your song – a drums track, a guitar track, a piano track, and one other.
  • Make the starting and ending measures 1, 33 for all 4 of these with fitMedia.
  • Make sure they are on 4 different tracks (the 2nd parameter of fitMedia).


We will be using a “loop” to more easily place tracks in our song. A loop runs a function for all instances of a given variable, in a certain range. We will be typing the following:


for measure in range(1,33):
       fitMedia(drums, 1, measure, measure+1)


In this code, “measure” is a variable that is storing the numbers in the “range” from 1 to 33.


range() is a function that takes 2 parameters, the start of the range (inclusive), and the end of the range (exclusive). Notice the colon (:) after the range. This is essential to let the program know that the whatever the next line of code following this is, it will only happen during the range given.


Notice that in my fitMedia function, it still takes the drums variable, and the track number is still a specific value (“1” in this case), but that we replaced the start and end measures with a variable called “measure” and “measure +1”.


Now, let’s put our fitMedia functions “inside” this loop to have them run in the range from 1, 33. Be sure to replace the specific values you HAD in your fitMedia functions for start and end measure with the variables “measure” and measure +1.


Now try changing the values of your range and seeing how easy it is to change all 4 functions at the same time.


Try adding 2 more instruments and functions with a different range, perhaps 17, 33?


Also, if you feel like you’re getting this and you want to move on, if range() takes 3 parameters, the third parameter is known as the “step” upwards, which is the amount it increases by.


That is, if you say:


for measure in range(1,33,4):
fitMedia(drums, 1, measure, measure+1)


It will play the drums track on measure 1, then skip 4 and play it on measure 5, then measure 9, then measure 13, then measure 17, then 21, then 25, then 29, and then it won’t place it on 33, because that is the exclusive end of the range.






Day 4 (7/15/14)


Even though I’m not here today, Julateh will be helping you continue to learn to program. Click on the link to the Code Editor above to open the EarSketch browser window. Click on the Files icon on the Toolbar on the left side of the screen and open the Music folder to listen to the EarSketch Sound Files. Remember your work flow from last week.



Then, if you had an account created, and you were able to save your script to the cloud, click on Load Script, above the code editing window, and click on the name of the song you saved.


If you did not save your script to the cloud (because you were not logged in), then Julateh can help you find where you downloaded it to. Usually it will show up in the Downloads folder. Then, copy the text of that file and paste it into the EarSketch code window.




For today, try to write as long a song as you can, with as many instruments as you want.


Some guidelines:

  • Choose variable names that accurately reflect the instruments you are using. If it is a drum sound, call it drums (or drum1, or drum2, or funkyDrums, or coolDrums, or whatever). Usually the sound files will have the name of the instrument in their file name.
  • Try for a song of around 32 measures! Think about how to use the start and end measure parameters of fitMedia to do that.
  • Try to have different instruments “come in” or, start, at different times. Maybe you have 2 versions of the same instrument, playing a different melody or a different beat at different parts of your song.
Have fun! See you on Thursday!



Day 3 (7/10/14)

Today we will write our first program!


Click on the link to the Code Editor above (unless it’s already open in your browser).


First, listen to a few of the sound files in your computer, and choose one that you want to hear.


In the code editor, type the name of the variable that you will use to call that sound file. If it’s a drum sound, call it drums. If it’s a guitar sound file, call it guitar.


In your code, after the line that says “setTempo(120)”, write:


drums =




Then, find the name of the sound file that you will be using in the folders on the left side of the window. Next to the name of the one you want, click PASTE, and it should paste the name after the equal sign.


You should see this:


drums = Y01_DRUMS_001


Now your program “knows” you have a sound file called “drums” and that whenever you type the word “drums”, it will play the Y01_DRUMS_001 sound file.




On a few lines down, type the words:





Inside the parentheses, you will type 4 different things, separated by commas:


fitMedia(soundFile, trackNumber, measureStart, and measureStop)      // This is the generic version.



Yours MIGHT look like this:



fitMedia(drums, 1, 1, 5)



That will place the “drums” file (the 1st parameter) on track 1 (the 2nd parameter), starting on measure 1 (the 3rd parameter), and ending on measure 5 (the 4th parameter).



Now click Run Script, and you should see and hear your code in the Workstation tab.







Day 2 (7/8/14):


Welcome back! Today we will begin to learn how to write programs with Python and use them to create songs.



First, make sure you are using the Google Chrome browser (it is a yellow, green, and red circle, and you can find it with the search icon in the top left corner of the screen, and typing in Google Chrome).


Before we start for today, please take 5 minutes to take a brief survey that I’m giving as part of the research I’m doing on the iLab. If you’ve already taken it for another class, you don’t need to take it again.



Now, click on the link to the Code Editor above, and wait for that page to load. Notice the 3 main tabs – Code Editor (where you write the code), the Workstation (where you can see the song that you are creating with your program), and the Combined View, which shows a combined view.




A program, or script, is a set of instructions given to a computer using words, symbols, and numbers that both humans and computers can understand. Typically, you will write your code in an IDE (integrated development environment), which can then “compile” the code, or, translate it into the 1′s and 0′s that cause the computer to do things.


All programs consist of statements, which are instructions that act on objects. These objects can be as simple as a number, a string of letters (words or sentences), or even other instructions, called functions. Think of a recipe: there are ingredients (the objects), and the actions you take on those ingredients, such as chop, mix, boil, etc, which are the functions.



All music is based on a set of patterns, of repeated sounds that change slightly to create different feelings or effects. In programming, something that changes is called a variable. Something that never changes is called a constant.
Constants are used for elements of your program that remain the same throughout the entire usage of your code. In a typical Python program, constants might be used to represent employee names, or any other value that would not likely change throughout the life of the program. For our purposes, the musical samples that we will be using to create our songs will be our constants. These come from a database that we have created, using sound files from professional music producers that we work with, such as Young Guru(the producer for Jay-Z), and a dub step producer named Richard Devine.


In Python programming, constants are sometimes called “immutables,” and are always CAPITALIZED.



Variables are elements of the code that change depending on information you declare, or that the program returns to the variable. In a typical Python program, variables might be used to represent employee salaries, or interest rates, or any other value that might change throughout the life of the program. These are always lower-case, or, if you have two words, they are joined together, with the first letter of the following words capitalized (this is also called camel case, like a camel’s humps).


e.g.: camelCase


For EarSketch, your variables will be used to store the information, or the CONSTANTS that are the musical samples. For instance, when you want to use a particular sound file for one of your instruments, you will declare that variable before you use it.




drums = Y01_DRUMS_001





In your code editor, add your name and the name of your song as a comment, by using the pound sign (#) in front of that line. That will tell the computer to not read that code, but we humans can read it. Then, for organization, add a comment in the main body of the code between the setTempo() function and the finish() function. This will be where we will assign our instrument variables to the sound sample CONSTANTS, and use our fitMedia() function to place them on various tracks in our piece of music.


Notice that right away when you load the code, it has some built-in, required elements:


-from earsketch import * – loads all of the “libraries” of required code elements

-int() – or, initialize, tells the code editor that a program is about to start

-setTempo() – sets the tempo, or speed, of the song

-finish() – tells the code editor that the program is over.



# Song Name
# Author


from earsketch import *




# Music





ALL of your code must be typed between setTempo() and finish(). If it isn’t, or if you delete parts of those lines, the code will not run.



Now, in the next line under the # Music comment, we will create our first variable. Type in the name of the first instrument you will use. This will be where we will declare our variable, and assign a value to it.


What you type does not matter, as long as it makes sense to you, and it is one single word (or two words in camelCase, like funkyDrums, or rockGuitar). If you want more tips on Python variable naming conventions, check out this w3resource page. (w3 is a GREAT tool for Python programmers, and it has resources for many many other languages as well. I would recommend bookmarking their main page.)


Then, type an = sign after the variable name, and put the name of the CONSTANT (sound sample), that you want that variable to “refer to.”


Like so:


# First Song
# Michael Madaio
from earsketch import *




# Music

drums = Y04_DRUMS_SAMPLE_1




Ok! Now that we’ve declared our variable, we have the “ingredients” that we’ll be using for this code. Next, we need to actually do something with it, and that’s where functions come into the picture.


Functions, much like variables, can be defined, or created by users to do basically anything that you want the computer to do. However, for most software systems, they come with a built-in, predefined set of functions, or their API (Application programming interface). This is the reference, or resource documentation that the programmers who created that software give to all of the programmers who use it. For instance, Facebook’s API lets programmers “embed” Facebook functions and interfaces into other programs.



For EarSketch, the main built-in function we will be using is called the “fitMedia()” function. This is the explanation for fitMedia():


fitMedia(fileName, trackNumber, startLocation, endLocation)



Adds an audio file to a specified track number. This function inserts the audio file as many times as possible between the specified measure numbers.



fileName (String)     – Audio file to insert on track, typically this is a constant variable from the Audio Loop Browser
trackNumber (Integer) – Track number to insert media file onto
startLocation (Float) – Location for where the initial soundfile will be placed
endLocation (Float)   – Exclusive location for the end of the soundfile(s) (e.g. File will not occur after this point)


# The following function inserts audio file on track two, measures 1 to 9 (e.g. File not included on measure 9).
fitMedia(HIPHOP_FUNKBEAT_001, 2, 1, 9)


Now, you try!



# First Song
# Michael Madaio
from earsketch import *




# Music

drums = Y04_DRUMS_SAMPLE_1

fitMedia(drums, 1, 1, 9)





How do you think you would add a piano to this?


By the time you leave today, you will have written your first program, and we will share our songs with each other!


Leave a Reply

Your email address will not be published. Required fields are marked *