CS 140 Fall 2009:  Introduction to Computer Programming

Course:  CS 140
Location:  224 Johnson Hall
Times:  Tues/Thurs 8:30-10:00
TA:  Nancy Decker (nkdeck07)
 Lisa Torrey (ltorrey)
Office:  106 Bewkes Hall
Hours:  Wed/Thurs 3:00-4:00
TA hours:  Thurs 7:00-9:00pm

About Work Policies Python

About the course
This course will introduce you to computer science, one of the most important fields of the 21st century.  It is a field with potential to help solve many important problems.  It is both challenging and rewarding, and it requires both technical precision and creative design.

In this course, you will begin to learn:
  • How computers work
  • How to write computer programs
While learning programming, you will also find out about exciting areas of computer science, such as:
  • Artificial intelligence
  • Bioinformatics
  • Computer games
  • Security
  • (and more)
We will be working primarily in Python, a high-level programming language that many people find easier to learn than other popular high-level languages.

Prerequisites:  None.  This course is intended for students who have not done any programming.
Textbook:  There is no textbook to buy.  Instead, I will direct you to online readings chosen specifically for each topic.

Project Description
This course has a final project instead of a final exam in order to let you explore an area of interest to you.  For this project, you will design and write a non-trivial program of your choice.

If you normally work with a partner, you may work together on the project, but you may also choose to work separately if your interests are in different areas.

  • A description of the program you want to write is due on Thursday 12/3.
  • A description of your progress and your code so far is due on Wednesday 12/9.
  • Final code is due at our final exam slot, which is Monday 12/14 from 8:30-11:30am.
  • During our final exam slot, you will briefly demonstrate your program to the class.
Your project is worth 20% of your grade. Of this, 5% will be for meeting the deadlines described above, and the other 15% will be for your code.  The code will be graded the same way homeworks are: half on correctness and half on style.

Ideas for topics
  • Animation:  a challenging animation with good use of lists and functions.
  • Interactive graphics:  a calculator program with buttons and text boxes.
  • Games:  a small version of Minesweeper or a simplified version of Tetris.
  • Artificial intelligence:  a better tic-tac-toe player.
  • Bioinformatics:  a program that builds an evolutionary tree based on DNA similarity.
  • Security:  a more powerful encryption method than the Caesar cipher.

You don't have to use one of these ideas-- you can propose an idea of your own as well.

If you are using pygame in your project, you will need to install the pygame library from here and check out this tutorial.

Current coursework

Tuesday, December 8:  Web search. Class examples: web_crawl.py, capital.py

Thursday, December 3:  Webpages and HTML. Class example: webpage.html

Tuesday, December 1:  Security. Class examples: break_caesar.py, permute_cipher.py, good_password.py

Thursday, November 19:  Bioinformatics. Class examples: make_dna.py, find_pattern.py, find_snp.py

Tuesday, November 17:  Artificial Intelligence (AI). Class examples: tictactoeAI.py

Thursday, November 12:  Computer games. Class examples: tictactoe.py

Tuesday, November 10:  Human-computer interfaces (HCI). Class examples: coordinates.py, drops.py, graphical_convert.py

Thursday, November 5:  Computer graphics & animation. Class examples: falling.py, snowfall.py, growing.py, tunnel.py

Tuesday, November 3:  More graphics in Python. Class examples: stoplight.py, face.py

Thursday, October 29:  Graphics in Python. Class examples: drawing.py

Tuesday, October 27:  In-class exam.

  • Remember to turn in your review exercises!

Thursday, October 22:  Review for the exam on Tuesday in class.

Tuesday, October 20:  Sorting. Class examples: filesort.py, compare_sort.py

  • The exam is coming up next Tuesday during class!

Tuesday, October 13:  File input and output. Class examples: files.py, wordcount.py

Thursday, October 8:  Searching. Class examples: search.py, new_months.py, compare_search.py

Tuesday, October 6:  Lists. Class examples: months.py

  • Reading for next class:  section 13.1 of this book chapter (searching algorithms)

Thursday, October 1:  Functions. Class examples: functions.py, probability.py, findprime.py

Tuesday, September 29:  Review and practice for the exam tonight at 7pm in Bloomer Auditorium.

Thursday, September 24:  Review and practice. Class examples: coinflip.py, testprime.py

  • The exam is coming up next Tuesday!

Tuesday, September 22:  Loop statements. Class examples: username_best.py, annoying.py, new_average.py

  • The exam is coming up a week from today!

Thursday, September 17:  If statements. Class examples: new_greeting.py, new_convert.py, username_better.py, guess.py

Tuesday, September 15:  Programs with strings. Class examples: username.py, backwards.py, savings_better.py, vowels.py

Thursday, September 10:  Programs with simple loops. Class examples: power.py, average.py, savings.py

Tuesday, September 8:  Programs with numbers. Class examples: convert.py, hypotenuse.py
Thursday, September 3:  Writing small programs. Class examples: hello.py, greeting.py
Tuesday, September 1:  How computers work
  • Homework for next class:  Answer these questions on your computer specs
  • Homework for next class:  Install Python on your computer using these instructions
Thursday, August 27:  Introduction to computer science

Course policies
  • Attendance is important.  I intend for class periods to provide experiences you can't get from reading.
  • Please turn off cell phones during class to avoid interruptions.
  • My office hours for this course are Wed/Thurs 3:00-4:00, but you can drop in or make appointments at other times.
  • If your learning or participation in this course may be affected by a disability, please talk to me about it early in the semester so that we can arrange appropriate accommodations.  I will do my best to ensure that everyone can learn effectively.
  • It is very important to me that you conduct yourself with academic integrity in this course.  Please refer to these examples of what that means.  If you are in any doubt, please ask.
Programming assignments
  • Weekly programming assignments will usually involve writing small programs in Python.  You will submit some things on paper and some electronically.  Programs will start small and simple and become more difficult as the semester progresses.  Towards the end, they may require significant amounts of time.
  • Late days:  You will have 4 late days that you may spend over the semester to turn in assignments late without penalty.  The purpose of these is that you won't have to ask for an extension if you have a difficult situation at some point during the course; it is meant to give everyone flexibility in a fair way. 
  • You may spend all your late days at once or split them up.  I recommend saving them in case a time comes when you really need them.  Once you run out of late days, you may not get credit for late work, though you may still get feedback.
  • Collaboration:  If you benefit from working with a partner on programming assignments, then I encourage doing so.  You may form your own pairs or sign up to be matched with someone.  Please consider these suggestions when working together.
  • Getting help:  Nancy and I have office hours and email addresses @stlawu.edu as noted at the top of the page.  My office hours are in my office (106 Bewkes), and Nancy's are in the Quantitative Resource Center.  There are also general TAs available as noted on the QRC page.  Finally, Nancy will share her AIM name with you if you want to talk to her that way.
  • Exams will involve writing programs like the ones in the homework assignments up to that point.
  • I have scheduled exams in the evenings so that it's possible to give you (essentially) unlimited time for them.
  • You may bring a single sheet of paper with whatever you want written on both sides to each exam.
  • If you miss an exam, see me as soon as possible.
  • If you find any significant problem with the grading of your exam, please come to my office with a written paragraph explaining the problem.
  • Instead of a final exam, we will have a project that lets you explore something in computer science that interests you.
  • Projects will be due on the last day of class, and we will do brief presentations of them during the final exam period
    (Monday Dec 14, 8:30-11:30am). 
  • Details and project ideas will appear as we reach mid-semester.
Grade proportions
  • Programming assignments:  50%
  • Exams:  30%
  • Project:  20%
  • Grade calculator as of 11/20

Academic Integrity
Your student handbook outlines the university's policies on academic honesty.  The university's main expectations are:
  • Collaboration should only occur with instructor permission.
  • Students should not receive unauthorized help on exams.
  • No one should claim credit for work that isn't theirs.

In this course, here are some specific expectations:

  • Students should work on programs either by themselves or in pairs, not in any larger groups.
  • Students in pairs should contribute equally to every program.
  • Students should not exchange or copy code.
  • Exams should be done completely individually.

Working in Pairs
Ideally, programming with another person will help you correct each others' misunderstandings, see alternate ways of approaching difficult programs, and learn with a broader perspective than you would alone.  A challenging class can also be much more enjoyable when you're working with others.  The very real possibility of these benefits is the reason I do encourage collaboration on homework.  To get the benefits, though, you have to go about collaboration the right way.  Here are some basic suggestions for doing so.

Before working with a partner:  Outline the program by yourself.  Some programs may be simple enough not to need pair programming at all.  Others may be difficult enough that you can only really contribute if you've done some thinking already.

While working with a partner:  Make sure that each partner takes control of the keyboard for about half the assignment.  It will be tempting to have the faster typer or the stronger programmer at the keyboard the entire time.  Resist the temptation!  Remember the point is not to finish the program in front of you as fast as possible; the point is for both of you to develop your programming skills.

After working with a partner:  Both partners should turn in the same code, and both partners' names should be in the files.

The official Python website is the definitive source for information, but below are some quick-reference guides.

Installing and Running Python

  • Go to http://www.python.org/download.
  • For Windows, download the "Python 2.6.2 Windows installer" and for Mac, download the "Python 2.6.2 Mac Installer Disk Image."
  • Find the file you downloaded, probably on the desktop, and run it. Click "Next" until it's done, and click "Finish."
  • Wherever your PC or Mac keeps your programs, find the Python 2.6 folder and open the program called IDLE.
  • What you have there is an interactive window, where you can run single lines of Python code at a time.
  • To put a program in a file, go to the File menu and select New Window, and type your program there.
  • To run your typed program, save it (File->Save) if you haven't already, go to the Run menu and select Run Module.

Coding in Python

This is the first semester that CS 140 is using Python, which means that the TAs may not be familiar with the language.  Don't be concerned though; Python has a great deal of similarity to Java, which the TAs will know.  They may need to consult the Python documentation about syntax differences, but the ideas are the same.  To make this easier, here is a quick-reference list of differences between Java and Python syntax.

Python is intepreted, not compiled.
Code can be run one line at a time in the interpreter.  It can also be run from a file, but there's no separate compile step as there is in Java.

Python can have code outside of any class or method.
While Python is object-oriented, it does not require a program to contain any classes or even a main method as Java does.

Python comments start with #
Unlike the // symbol in Java.

Python variables do not have to be declared.
You can introduce and use a Python variable without declaring a type as in Java.

Python does not use semicolons.
Lines do not have to end in semicolons as in Java.  There are some regular colons in Python, though -- at the top of an indented block for a loop, function, etc..

Python does not use brackets.
Loops, functions, etc. do not use any brackets.  Instead, you indicate what is inside a loop, function, or other block purely by indentation.  The convention is to have code start with 0 spaces, to put code inside a top-level loop 4 spaces in, to have the next level 8 spaces in, and so on.

Whitespace at the beginning of the line matters in Python.
Since indentation is meaningful, each line must have exactly the right number of spaces before it, or there will be an error.  It could be an interpreter error, say if the first line of a program has a space in front of it, or the code could just not work as intended, say if a line meant to be inside a loop doesn't have enough spaces in front of it.

Python arrays are called lists.
They have lots of built-in functions associated with them that Java doesn't, allowing you to do things like sorting and accessing a sub-list.  There's also a built-in data structure called a dictionary, which is a hash.

Some mathematical operators are different.
Python does not contain the increment (++) and decrement (--) operators, but it does include exponentiation (**) and floor division (//).

Python function headers have fewer words.
A Python function header looks like def function_name(param1, param2):
There are no modifiers or variable types as in Java.