Creating a Complete Python Program

You'll learn how to copy files into your account from an instructor's directory, and you'll write your first complete Python program.





Downloading the .emacs file

The first thing you'll do is download a file that will configure the emacs editor we'll be using, to customize the way the emacs program behaves. While in your home directory, copy the .emacs file into your current folder by using the cp command below. (Remember, cp simply stands for "copy.")

cp /afs/umbc.edu/users/k/k/k38/pub/cs201/.emacs .

There are three parts to this command, and all three are important:

  1. "cp" is the command, and in this case it stands for copy
  2. "afs/umbc.edu/users/k/k/k38/pub/cs201/.emacs" is where the file you are going to copy is located
  3. "." (a single period) is where the file will be copied to in your account
    (In this case, the location is "." which means it will be copied to the current folder, and with the original filename.)

The period "." in front of the file name means that the file is a "hidden" file. If you use the command ls, you won't see it listed. To check that you successfully copied the file, you need to use the command "ls -a". The -a means "all" and will show all the files in that directory, even hidden ones.





Creating a file from scratch

Next, you are going to create your first complete Python file, entirely from scratch. First, create the lab2 folder using the mkdir command — the folder should be inside your Labs folder. (If you need a reminder of how to create and navigate folders, refer to the instructions for Lab 1.)

Next, create a file called lab2.py by opening it up for editing with emacs:

       emacs lab2.py

You'll want to reproduce all of the text from the image below inside your lab2.py file, making sure to include all of the "#" signs, and following the capitalization shown.

Quick note about collaboration in labs: because you are working with the other students in your lab section, we do not require that you record usernames in the lab file's collaboration section. You should still not copy code, and you should not type on another student's keyboard. You should also never email another student code (from a lab or a homework assignment) for any reason.





About the header comment

The pound symbols "#" you have in the lab2.py file are used to tell Python that any text on that line after the pound sign is a comment. Comments are ignored by Python, and the text following a pound sign does not need to follow any of Python's syntax rules. Comments are useful for the person reading the code (you, your TA, your instructor, etc.).

Programmers use comments to explain what the code is doing, to leave notes to themselves, and to document things about the code. For example, the comments at the top of the file are called a "header comment block," and record who created the file, when, and what the file is supposed to do.

We'll talk more about comments throughout the semester, since they are an incredibly important part of programming and being a good programmer.