Introduction to Computer Science using Python


Course Information

Section 4: TR 9:55–11:10, Sci Cntr 240
Professor: Andrew Danner
Piazza: CS21 Q&A forum
Office: Sci 247
Office hours: You can stop by whenever my door is open, or email me for an appt.

Other Sections:
Zachary Palmer (TR 8:30am–9:45am)
Rich Wicentowski (TR 9:55–11:10)
Jeff Knerr (MWF 11:30–12:20)


Welcome to CS21. This course will introduce fundamental ideas in computer science while also teaching you how to write computer programs. We will study algorithms for solving problems and implement solutions in the Python programming language. Python is an interpreted language that is known for its ease of use. We also introduce object-oriented programming and data structures. A deeper coverage of these topics will be presented in CS 35.

This course is appropriate for all students who want to learn how to write computer programs and think like computer scientists. It is the usual first course for computer science majors and minors. Students with advanced placement credit or extensive programming experience should place out of this course and instead begin with CS31 or CS35.


There is no required textbook for this course. There are, however, required readings! See the Schedule for each week's reading assignment. We will primarily be using the online book How to think like a computer scientist: Learning with Python by Elkner, Downey and Meyers.

Here are a few other useful online python resources:

Goals for the course:

By the end of the course, we expect that you will have developed the following skills:


This is a tentative schedule; it may change as we go.

Sep 01

  Introduction to Python and Unix
  • python and unix
  • data types
  • variables, assignment
  • calling built-in functions
  • print(), type(), int(), float(), str()
  • user input: raw_input()
  • for loops, sequences, range()
  • writing and running a program
In class
Lab 0: unix, editing

Sep 03


Sep 08

  Writing simple programs
  • def main()
  • more for loops
  • accumulator pattern
  • strings and lists: mutable vs immutable
  • indexing, slicing, len()
  • print(), print formatting
  • from math import *
In class
Lab 1

Sep 10

Drop/add ends (Sep 11)


Sep 15

  • boolean type
  • comparison operators (<, >, ==, !=, etc)
  • logical operators (and, or, not)
  • mod operator
  • if/elif/else
  • nesting
  • the "in" operator
  • string comparisons
In class
Lab 2

Sep 17

Quiz 1


Sep 22

  First functions, while loops
  • writing simple functions
  • arguments, parameters
  • while loops
  • exceptions (try/except)
  • random numbers
In class
Lab 3

Sep 24


Sep 29

  Graphics, Using Objects
  • intro to objects
  • intro to graphics
  • RGB colors
  • object.method()
  • more practice with functions
  • mouse and keyboard input
  • animation
In class
Lab 4

Oct 01

Quiz 2


Oct 06

  Fruitful Functions
  • more practice with functions
  • incremental development
  • boolean functions
  • stack diagrams
  • passing lists to functions
In class
Lab 5

Oct 08


Oct 13

Fall Break

Oct 15


Oct 20

  File IO, TDD
  • reading/writing files
  • top-down design
  • function stubs
  • list-of-lists
  • string and list methods
In class
Lab 6

Oct 22

Quiz 3


Oct 27

  • linear search
  • analysis of algorithms
  • binary search
  • search info???
In class:
Lab 7

Oct 29


Nov 03

  • selection sort
  • analysis of algorithms
  • insertion and bubble sort
  • idea of merge sort, recursion
  • sorting info???
In class:
Lab 8

Nov 05

Quiz 4

CR/NC/W Deadline (Nov 06)


Nov 10

  • recursive call
  • base case
  • leap of faith...
  • graphics examples
  • back to merge sort
In class:
Lab 9

Nov 12


Nov 17

  Classes and Objects
  • creating our own objects
  • instance variables
  • self, __init__, __str__
  • methods
  • getters/setters
  • class writer vs class user
  • interface/information hiding
In class:
Lab 10

Nov 19

Quiz 5


Nov 24

  More Classes
  • more examples
In class: MW
Lab 11

Nov 26



Dec 01

  Linked Lists
  • python list vs linked list
  • Node() class
  • LinkedList() class
  • linked list methods
  • analysis of algorithms
In class:
Lab 12

Dec 03

Quiz 6


Dec 08

  Wrap up

Dec 11

Final Exam 7pm-10pm Sci 101

Grading Policies

Grades will be weighted as follows:
40%Lab assignments
25%Final Exam
5%Class Participation

Quiz policy

Quizzes will be given at the beginning of class on the days posted on the Schedule. Please look over these dates carefully and contact the professor in advance if you cannot be in class for a quiz.

Lab Policy

This course features weekly lab assignments which are the largest component of your course grade. Lab attendance is required by all students, unless you have already completed and submitted the lab assignment for the week. You must attend the lab session for which you are enrolled:

Weekly Lab Sessions
CS21 A 1:05—2:35pm Tuesdays Wicentowski Science Center 240
CS21 E 1:05—2:35pm Tuesdays Danner Science Center 256
CS21 B 2:45—4:15pm Tuesdays Kutty Science Center 240
CS21 C 1:15—2:45pm Wednesdays Palmer Science Center 240
CS21 D 3:00—4:30pm Wednesdays Palmer Science Center 240

Lab assignments will typically be assigned in class at the beginning of the week and will be due before midnight on Saturdays. You are strongly encouraged to start early and to attend the study sessions for extra practice.

You will submit your assignments electronically using the handin21 program. You may submit your assignment multiple times, and a history of previous submission will be saved. You are encouraged to submit your work regularly.

Late assignments will only be accepted if you contact the professor at least a day before the deadline with a legitimate reason for needing extra time, such as an illness or needing to leave campus.

Even if you do not fully complete an assignment, you should submit what you have done to receive partial credit.

The cs labs are open 24 hours a day, 7 days a week for you to use for CS21 lab assignments.

Academic Integrity

Academic honesty is required in all your work. Under no circumstances may you hand in work done with (or by) someone else under your own name. Your code should never be shared with anyone; you may not examine or use code belonging to someone else, nor may you let anyone else look at or make a copy of your code. This includes, but is not limited to, obtaining solutions from students who previously took the course or code that can be found online. You may not share solutions after the due date of the assignment.

Discussing ideas and approaches to problems with others on a general level is fine (in fact, we encourage you to discuss general strategies with each other), but you should never read anyone else's code or let anyone else read your code. All code you submit must be your own with the following permissible exceptions: code distributed in class, and code found in the course text book. In these cases, you should always include detailed comments that indicates on which parts of the assignment you received help, and what your sources were.

Failure to abide by these rules constitutes academic dishonesty and will lead to a hearing of the College Judiciary Committee. According to the Faculty Handbook: "Because plagiarism is considered to be so serious a transgression, it is the opinion of the faculty that for the first offense, failure in the course and, as appropriate, suspension for a semester or deprivation of the degree in that year is suitable; for a second offense, the penalty should normally be expulsion." Be aware that we will be routinely running plagiarism detection software on the lab solutions of students from all sections of CS21.

Please contact me if you have any questions about what is permissible in this course.

Student Support

Lauri Courtenay is the CS Department's Academic Support Coordinator. She will be working closely with our student mentors, also known as Ninjas, to help you learn how to program and think like a computer scientist. The CS21 Ninjas will assist me in class and run evening study sessions in Sci 256. The CS21 Ninjas (student mentors) are: Rachel Diamond, Daniel Redlemeier, Diana Martschenko, Caleb Ho, Emily Wu, Daniel Pike, Carlo Sivilotti, Charlotte Raty, Michael Song, and Reba Magier

Study Sessions

You are invited -- and encouraged -- to participate in Ninja evening study sessions to prepare for quizzes, to discuss programming concepts, and to get friendly assistance in working on lab assignments. Our CS mentoring team is dedicated to helping students, who have no prior knowledge of computer science, learn to program in Python while keeping their senses of humor intact. As an added bonus, free snacks will be provided at the sessions. The sessions are held:

Weekly Evening Ninja Sessions
Tuesdays 7—9pm Sci Center 256
Wednesdays 7—10pm Sci Center 256

Accessing the CS labs after hours

You can use your ID to gain access to the computer labs at nights and on the weekends. Just wave your ID over the microprox reader next to the lab doors. When the green light goes on, just push the door to get in (the door knob will not turn). If the green light doesn't go on, then we need to enter your microprox number into the system. Email (or see Bridget) if you have problems with this. If the building is locked, you can use your ID to enter the door between Martin and Cornell library. For this class, your ID will give you access to the labs in rooms 238, 240, and 256.

Academic Accommodations

If you believe that you need accommodations for a disability, please contact Leslie Hempling in the Office of Student Disability Services (Parrish 113) or email lhempli1 to arrange an appointment to discuss your needs. As appropriate, she will issue students with documented disabilities a formal Accommodations Letter. Since accommodations require early planning and are not retroactive, please contact her as soon as possible. For details about the accommodations process, visit the Student Disability Service website.

To receive an accommodation for a course activity, you must have an Accommodation Authorization letter from Leslie Hempling and you need to meet with me to work out the details of your accommodation at least one week prior to the activity.

You are also welcome to contact me privately to discuss your academic needs. However, all disability-related accommodations must be arranged through Leslie Hempling in the Office Of Student Disability Services.

How to Succeed in CS 21

Programming Style

Programming is not a dry mechanical process, but a form of art. Well written code has an aesthetic appeal while poor form can make other programmers and instructors cringe. Programming assignments will be graded based on style and correctness. Good programming practices usually include many of the following principles:

Also, look over the Python Code Style Guide for more details and some examples of good code style.

Links that are related to the course may be posted here. If you have suggestions for links, let me know.

Python Tutor
Vi Quick Reference
Python style guide From Prof. Tia Newhall
Using Unix
Basic Unix Commands
Python Documentation (Note: we are using v2.7)
Graphics reference
How To Think Like a Computer Scientist: Python for Software Design
Dive Into Python
(A Semi-Official) Python FAQ Zone
emacs beginner's guide