Now it's time to seriously write some code. Start by right clicking on this link and select save as. Make sure to save this file to the PythonLab1 directory that we made earlier. Head back to the shell and enter the ls command to make sure that the file made it into our PythonLab1 directory.


Alonzos-MacBook:PythonLab1 alonzo$ ls
virus.py
        

First, take a look inside the virus.py file. We will be editing the python file in something called a text editor (guess what a text editor does...). There are many text editors available, (NotePad++, Emacs, Xcode, TextMate, etc.) but in this lab we'll be using SublimeText 3. If you're working on a lab computer, you can find Sublime in the Applications folder. Otherwise, any text editor (not Microsoft Word!) will do.

Open up Sublime and then open virus.py. Make sure to read the comments at the top of the file and then take a brief glance at the code, but don't worry about it too much for right now. Also, make sure to set the variable called your_name just below the comments. For example, your_name = "Alonzo" (make sure your name is inside quotes as this is how Python designates text).

Head back to the shell and you can try running this file by entering python3 virus.py as shown below:


Alonzos-MacBook:PythonLab1 alonzo$ python3 virus.py
        

Next try running the first exercise by entering python3 virus.py first_even_nums 5 (if it's working this should print the first 5 even numbers, starting with the number 2):


Alonzos-MacBook:PythonLab1 alonzo$ python3 virus.py first_even_nums 5
2
4
6
8
        

Uh oh...it looks like we've only printed the first 4 even numbers. Head back to Sublime and edit the function called first_even_nums so that we get the correct behavior:


Alonzos-MacBook:PythonLab1 alonzo$ python3 virus.py first_even_nums 5
2
4
6
8
10
        

On the next page you'll learn how to define functions of your own!