20.179

From OpenWetWare

(Difference between revisions)
Jump to: navigation, search
m (Random Notes)
Line 80: Line 80:
#Day 6:
#Day 6:
#* With classes, draw analogies to real-life "classes" in our conceptual thinking.
#* With classes, draw analogies to real-life "classes" in our conceptual thinking.
-
#** You can have subclasses and superclasses.
+
#** You can have subclasses and superclasses.  
 +
-- this section by Justin

Revision as of 16:46, 29 September 2006

"20.179": Introduction to Computer Programming

Image:Monkeys.jpg

    Home        Syllabus        Assignments        Expectations        Materials       

Contents

Introduction to Programming, January 2007

This student-run course ("20.179") is desgined to provide an introduction to computer programming for those with absolutely no programming experience. The course focuses on the thought process behind writing programs, and aims to separate the tasks of algorithm design and implementation. 20.179 is designed for sophomores in Biological Engineering, but will benefit anyone who seeks an introduction to computer programming.

Workload

Two hours a day for 9 days should be sufficient, depending on the amount of material we want to include. Problem sets would be given nightly, collected the next day, and graded, and would be designed to take no more than an hour to complete. They would also be discussed at the beginning of class for ~10 minutes each day as a review of the previous material.

WORK IN PROGRESS - 9/28 18:15 EST

List of Concepts

  1. Thinking in Algorithms
    • What is an algorithm?
    • What tools are there?
      • Data structures: int, float, str, char (save list, dict for later)
      • operations: +, -, concatenate, =, etc.
      • logic: ==, !=, <, >, >=, <=, or, and, &, |, etc.
    • Python IDLE GUI: intro to error messages and the debugger
    • "Hello World" in Python versus some other examples
    • Intro to Python online help
  2. Common progamming instructions
    • Conditionals: if...elif...else
    • Simple algorithms with if...else
    • Loops - a conditional that runs i times or until a condition is true
      • For vs. while (same result, different logic and code)
    • Several examples with loops/if...else
  3. Tools for decomposing difficult problems
    • Concept of a function as an independent algorithm
    • Pseudocode functions - miniature programs
    • Writing and using functions in Python
  4. More advanced manipulation of data types
    • Re-introduce Python help
    • Discuss a problem that requires use of built-in str functions, then find those and implement it
    • Introduction of list and dict types
    • File I/O and runtime user input (raw_input())
    • Type casting
  5. Recursion and computational time
    • Mathematical recursion - factorial, etc.
    • Recursion in computational algorithms
    • Speed - intuitive fact() function is O(2^n) - but this can be corrected!
    • The dorm arrangement + prefs list problem, also 2^n, but can't be changed.
  6. Classes
    • Why are they useful? Makes representing complex data easy
    • Several non-coded examples
    • Coded example with basic syntax (___init___, easy member functions and data structures)
  7. Anything else we want to cover
  8. 2-3 day Project (groups of 2-3)

Random Notes

  1. Day 1:
    • Distinguish writing a .py file and running it vs. just typing your commands into the >>> prompt.
    • With data types: note that each data type has a set of "methods." No need to go into great detail, but get students used to the idea that your type defines what sorts of things you can do. For instance, strings allow you to "find."
      • No one memorizes all of these methods - they're right there in Python help!
    • Comments use the pound sign (or multiple pound signs). Alt+3 is comment out, alt+4 is uncomment. Leave notes for future reference (and your TAs).
    • Variables and variable names - how to choose good names (too long = you'll mistype = waste time debugging; too short = what is this variable again?), and naming conventions (don't use spaces ..).
    • Logic vs. operations: == is not = --> distinguish "store this into this variable" and "is this equal to this?" Note that strings (and everything else) can be equal, not just numbers.
    • With the basic types: note that they can be interconverted. str(3) makes '3'.
      • Just a note to ease frustration: use \' to type an apostrophe in a string! Also, you can use " or ' to make a string, or three apostrophes for a multiline string (don't scroll off the edge of the world to read your paragraph-long string ...)
    • With basic operations: the divide symbol currently does this stupid "floor" function. You need to be careful about this! But it'll probably change in the next Python release.
    • 50% or more of programming is debugging. What's the fastest way (besides "ask a friend")? How to use "print" to your advantage: you can't diagnose a disease in the liver by looking at someone's clothes.
    • Python's "white space" thing - emphasize the importance of lining up your lines!
  2. Day 2:
    • Loops: "for" may be more annoying at times, but "while" can make your computer crash ... how to prevent the infinite while loop before it happens.
    • I think we should introduce lists, at least, by day 2. They're almost indispensable. Either that or introduce tuples like (1,2,3). Some way to deal with groupings. For loops especially like to take in lists. The range() function makes a list.
      • Make note of how the for loop syntax works - it's so different from language to language. for variable in thisRange:
      • Don't use the same variable for nested for loops, but it's fine for subsequent ones.
      • Distinguish using the list's ELEMENTS vs. the list's INDICES as the for loop iteration. Suppose myList = ['cat']. If we say " for i in myList," i becomes 'cat.' If we say 'for i in range(0,len(myList)),' i is 0. This is a key difference if we want to call myList[i]: the former will fail. There are times when each might be appropriate.
      • Note that everything in Python likes to start counting from 0!
  3. Day 3:
    • When discussing basic functions (we need to keep it really simple!), also note what a "module" is. No need to make modules, but know how to use the ones in Python. Note that ALL .py files can be modules!
      • For instance, suppose we want the date and time. It's very simple if we just type "import dateTime" at the top and use the various date functions.
  4. Day 4:
    • As I mentioned earlier, I think lists should be introduced on Day 2.
    • File I/O: you can directly feed, or you can pickle stuff, too. You can name your files however you want!
    • Dictionaries: keys vs. values. Keys can be numbers or strings, but not lists.
    • You can have a list of lists of lists, or a dictionary with lists as the values, or a dictionary of dictionaries.
  5. Day 5:
    • Huh? Dorm arrangements?
  6. Day 6:
    • With classes, draw analogies to real-life "classes" in our conceptual thinking.
      • You can have subclasses and superclasses.

-- this section by Justin


Comments? Suggestions?

WORK IN PROGRESS - 9/28 18:35 EST

Personal tools