2010 September 14 / jj|d|a|v|i|s|@|c|a|r|l|e|t|o|n|.|e|d|u

Assignment: Introduction

Carleton College CS 201, Fall 2010, Prof. Joshua R. Davis

Introduction

This assignment is short and simple, I hope. It is due by noon on Wednesday.

Read the Syllabus

We did not go over the syllabus in class, but you are responsible for knowing everything on it. For example, how do you activate your late pass? What task must you complete sometime during the first two weeks of class?

Test Your Computer Setup

Go to a Carleton CS lab such as CMC 306 or CMC 304. Start a computer into Mac OS X (if you can't find one already running it) and log in. There are four applications that we'll use heavily. All four should be in your Dock; if not, then find them and put them there. Ask for help if you need it.

First we're going to edit and save a Python program. Open TextWrangler and enter the following Python code into a new text document.
# 2010 August 29 by Joshua R. Davis

import random

def factorial(n):
    """The input n is a nonnegative integer. Returns the factorial n!."""
    if n == 0:
        return 1
    else:
        return n * factorial(n - 1)

if __name__ == "__main__":
    for i in range(6):
    	# Generate a somewhat random integer between 0 and 20 (more like 0 and 19).
        n = int(20.0 * random.random())
        print factorial(n), "=", n, "!"
    # Launch the help viewer for factorial (press Q to exit).
    help(factorial)

Near the bottom of the code is a loop that fires 6 times. Change 6 to some other small integer, such as the number of letters in your first name. At the top of the file is a comment giving the revision date and a list of authors. Change the date to today's date, and add yourself as an author. Save the document as intro.py.

Now we're going to run the program. Open Terminal. Navigate to the directory (folder) where you saved intro.py, using these basic Unix shell commands:

Once you've navigated to the correct directory, enter python intro.py to run your Python program. It should print out some numbers and then launch the help viewer. When you want to exit the help viewer, press Q; then you can see the numbers again. Make sure that you understand what every line of code does. If you don't, then ask someone for help.

Finally, submit your work using the following steps. Warning: Once you've submitted a file, you cannot edit or delete it.

Understand Good Python Style

The code I gave you above exhibits what I call Good Python Style:

In this course, every piece of code that you write is required to exhibit Good Python Style.

Send Me E-Mail

Please send me a brief e-mail message with the following information. (My address is at the top of the page.)

  1. name
  2. home town/country
  3. expected year of graduation
  4. possible major(s)
  5. Why are you taking this course?
  6. Have you taken CS 111 at Carleton? Which programming languages do you know?
  7. Did you have any problems with the earlier parts of this assignment?
  8. Anything else you want me to know?