8/17: Intro to class 8/19 int, float, string integer division functions, parameters identifiers and expressions operators vs operands string math (+ and *) myro Graphics type( ) int( ), float( ), str( ) GraphWin("Name", w, h) Point(x,y) var.draw(graphWin) Circle( point, radius) Line(p1,p2) 8/21 file vs shell comments and collaboration statement syntax vs semantic error (mention) interpreter (shell) Order of adding points/ shapes significant for Graphics for loops, wait, range, conditionals (mentioned briefly) hex, rgb colors raw_input(string) dynamically typed language Week 2: 8/24 format specifier, print statements "%.2f" % 123.22321, f = float, s= string, i = int tuples (mentioned briefly) function - name that points to code calling functions ie. func( ) with the parens blocks, indentation parameters local variables print vs return scope, global vs local and shadowing von Neumann architecture vs Harvard architecture w/ focus on von Neumann counting - tallies, Roman numerals, positional numbering (base 10) 8/26 Bases 2,8,10,16 bits, bytes booleans 8/28 Review functions and variables Libraries/Modules (myro, math) ** for power recursion conditionals Week 3: 8/31 conditionals in depth < > == >= <= != comparison operators booleans (True, False) not, or, and truth tables (for and and or) modulo operator % for remainders while loop base cases (for looping and recursion) timeRemaining(sec) function 9/2 return (ends functions) algorithms (powerpoint) history of computing (powerpoint) accessing strings str[1] iterating over strings (for loop), indexing using variables (for x in str) for loop range(num) function 9/4 hex to decimal conversion (review) return vs print (review) while and for loops (review, syntax, how to use) range(num) function, num is exclusive string slices str[0:2] getPixels(pic), setRed/Green/Blue(pixel, value), show(pic), makePicture(file), pickAFile(), getRed/Green/Blue(pixel), len(aStr) function, indexing with negative numbers str[-2] Week 4: 9/7 Holiday 9/9 Review: Pixels/pictures, while/for loops, str formatting, hexadecimal try except introduced 9/11 Test Review try except in detail Week 5: 9/14 Test 9/16 General Test issues (str vs boolean, capitalization matters, else not required with if) Robot sensors and actuators: getIR(), getLight() 0=more light, getBattery(), getStall(), getName() on fluke: getObstacle(), takePicture(), getBright(), Actuators: beep(time, hz, hz), motors(l,r), translate(num), rotate(num), setLEDBack(power), setLEDFront(power), joyStick(1=show sensors) 9/18 gamepad() compound data types (strings and lists) accessing and slice: aStr[0], aStr[0:3], aStr[0:6:2] parsing commands from strings (for loop to decode "ffbbllr" on the robot) the 'in' keyword index with while loop: while(index < len(str)): string module (digits, hexadecimal, letters, lowercase) Python API converting to and from ASCII/char ord("c") chr(67) Week 6: 9/21 String Review accessing/indexing/slicing lists: aList[0], aList[0:3], aList[0:6:2] lists are mutable, strings are immutable aList[0] = "val" good, aStr[0] = "C" error aliasing vs cloning (and using the slice operator to clone a list) using for loop to iterate over items in a list concatenation for str and list (both create new object), but can only concat. list with list cloning newList = oldList[:] id(object) to see if clone or alias List functions: aList.append(item), del aList[0], aList.sort() 9/23 aStr.find("val") review SSH and terminal: ls, permissions (user/group/other and r/w/x) ls -l for full info writing minimum and average functions for lists testing using small, computable test cases, checking edge cases (ie empty list) tuples why to use tuples: faster than lists, some data types (dictionary) require immutable keys tuple assignment: a,b = (5,6) 9/25 Pong: making a bouncing ball using graphwin, while loop, and conditionals for checking walls integrating random values (pickOne(1,5,9) and randomNumber) into pong adding multiple balls using lists and for loops code on course website Week 7: 9/28 HTML and CSS Python file i/o f = open("myFile.txt", "w"), f.write("line"), f.close(), \n, \t modes: w, r, a (write, read, append) note: f.write only takes in strings Example: getting light values, saving to file, outputting to website OS module: os.getcwd() (get current working directory), os.listdir(path) lists all files and dirs at path specified 9/30 reading files: f = open("myfile.txt", "r") f.read() f.readline(), f.readlines() \n = new line character (single character, len('\n') = 1) f.read(num of chars), aStr.split(char) curson location - file knows current location using a file to pass commands to a robot copying data from one file to another: contents = in.read(), out.write(contents) use a for loop to copy x chars at a time 10/2 Friday - notetaker gone. Week 8: 10/5 - school holiday 10/7 nested lists dictionaries: aDict = {} aDict[key] = value aDict.get(key,default val) aDict.has_key(key) dicts print as: {key:value, key:value} recursion, using Fibonacci - redundant work in fib recursion using dict to store fib values to prevent repeated work global variables (need to be specified in function, else creates new local) longs Pictures: takePicture(), savePicture(pic, "name.gif"), loadPicture("name.gif"), getX(pixel), getY(pixel), getPixels(pic), getWidth(p), getHeight(p), getPixel(p,x,y), setRed(pix, color), getRed(pix) robot pics are 256 x 192 pixels using for loops and getPixels(pic) to iterate over pics 10/9 Review of all concepts thus far Week 9: Monday - 10/12 Test Wednesday 10/14 Pictures, pixels, drawing lines, drawing rectangles (nested for loop) Computer vision: finding colors, finding center of picture Friday 10/16 Review of pixels/pictures and file I/O findRedPixels example Week 10: Monday 10/19 HW6 topics/questions, file I/O review line.split(delimiter as string) Wednesday 10/21: Decoding barcodes (powerpoint): convert image to white/black, scan a line near the center, convert line to list grouped by like pixels in form (number, color) IE: (4,255),(8,0),(3,255) Friday 10/23: Barcodes Cont. Remove error pixels, where number of pixels of color = 1 IE: (1,255), Decide if bar is wide or narrow (determine threshold for bar length): sort list, pick 1/2 and 3/4 for narrow, wide respectively Decode list to string of B, b, W, w depending on if white/black, WIDE/narrow Use dictionary to pick correct symbol NOTE: all code is posted on the website, this scenario was supposed to illustrate breaking a complicated problem into manageable parts Week 11: Monday 10/26: Searching and sorting Big O - upper bound to functions run time (worst case) linear search O(n) binary search O(log n) binary tree, each level has twice as many elements as previous level Exponents and logarithms x = B^y ~ y = log subB (x)... sorry, dont know how to do subscript Graphs of different searches and sorts ( n, n^2, log n) Bubble sort O(n^2) - dont worry about implementation Insertion sort O(n^2), 4 times faster than bubble sort, inserts items into correct location of already sorted sublist Insertion sort code shown: posted on website Wednesday 10/28: Crossfading images - going from all a to all b over time using increasing/decreasing fractions of a and b Big O O(1) O(logn) O(n) O(nlogn) O(n2) Merging 2 sorted lists O(n) merge sort, start with lists of 1, merge them together O(nlogn) Quicksort, can be done in place, grows the sorted list and puts next item in correct place O(nlogn) All sorting algorithms on class website Friday - 10/30 Big O review HW 7 (Special Effects) Questions Week 12: Monday - 11/2 Determining the complexity of an algorithm Controlling multiple robots: robot1 = Scribbler('comport') robot2 = Scribbler('comport') robot1.beep(1,880) Homework 7: for loops for modifying picture makeColor(r,g,b) setColor(color) Functional Programming: higher order function - can take functions in as parameters and can return functions as return value identifiers (variables) can point to functions Map, Filter, Reduce (more detail Wednesday) Wednesday - 11/4 Functional Programming Identifiers can point at functions: myFunc = abs Higher order function - functions that work on other functions (takes fcn as parameter) map(isEven, myList) - applies the function to each element, returns list of results filter(isEven, myList) - takes fcn with bool return val, returns new list with element that were True reduce(mult, myList) - takes fcn that reduces 2 items to 1 and applies to all items in a list: returns 1 val lambda functions: definition: lambda param: evaluation that has return value ex: lambda aNum: aNum%2==0 Friday 11/6 function that prints all comments: read in a file, print all comments (use line.find(#)) on website do it with functional programming: reduce(lambda s: "#" in s, lines) map(lambda s: s[s.find("#") : ], comments) Errors/Exceptions: try,except Recursion: Drawing the stack, keeping track of variables, code executes before/after fcn call Week 13: Monday - 11/9 tagCloud Program: make an html page of most frequently used words in a large text file All source code online named parameters - function takes in multiple optional parameters ex: word.sort(key = fcn) 11/11 tagCloud cont. - converting code to HTML page (source online) Eliza chatbot implemented in python ngram generator: take n letters and predict the next letter n letters as key in dictionary, potential letters that follow it as values in dict, pick one at random 11/13 test review Week 14: Monday: 11/16 test Wednesday 11/18: ngrams (code on website) n letters as key, 1 letter as value (the letter that follows the n), put in dictionary algorithm picks one of the values at random given a key went over writing code to read/write ngram output write function that reads a text file and makes a dictionary of ngrams write a function that takes the dictionary and generates text Friday 11/20: JavaScript powerpoint (on website) similarities and differences with python JS generates code for website (clock, text, html) Week 15: Monday 11/23: Objects (code on website): Constructor: def __init__(self, params): self: pointer that points at the instance of an object all methods must take self as the first parameter def __add__(self, param): overloads the "+" operator so that you can "add" objects inheritance: Animal -> Rabbit, Fox, Bear subclasses have shared characteristics of superclass class Rabbit(Animal): "Animal" inside the parenthesis signifies that rabbit inherits from Animal Wednesday 11/25: Quicksort using filter to make it parallizable (see video). Friday 11/27: No class, school holiday. Week 16: Review for the Final.