Week 3 Notes
Week 3 Notes CS 1110-002
Popular in Intro to Computing using Python
verified elite notetaker
Popular in ComputerScienence
This 4 page Class Notes was uploaded by Eunice on Saturday February 13, 2016. The Class Notes belongs to CS 1110-002 at Cornell University taught by Lee, Van Loan in Spring 2016. Since its upload, it has received 23 views. For similar materials see Intro to Computing using Python in ComputerScienence at Cornell University.
Reviews for Week 3 Notes
Report this Material
What is Karma?
Karma is the currency of StudySoup.
You can buy or earn more Karma at anytime and redeem it for class notes, study guides, flashcards, and more!
Date Created: 02/13/16
CS 1110 Spring 2016 Lee and Van Loan February 9, 2016 3. logical/Boolean operations o a Boolean expression can be stored in a variable (the result of the expression will be stored) x y x AND y true true true true false false false true false false false false x y x OR y true true true true false true false true true false false false and: both statements must be true for the overall statement to be true o a<=x and x<=b o is the same as o a<=x<=b or: at least one of the statements must be true for the overall statement to be true not: o not true = false o not false = true 4. o function implement a function: package a computational idea so that others can use it m = fct(x,y) fct: name given to a function x, y: both are arguments o arguments may be expressions python functions: max, min, abs, round o modules common: math, string, random, numpy, scipy, timeit, urllib2, PIL (image processing), datetime to get help: >>> help (‘whatever I need help on’) to access math module >>> import math >>> print math.sqrt(4) 2 this is dot notation o advantage being that if you are using multiple modules that each have functions with the same name, then dot notation clarifies to access a function in the math module >>> from math import sqrt >>> print sqrt(4) 2 >>> from math import sqrt, pi, cos, log [just give me what I need] >>> from math import * * imports all functions functions: math.floor, math.ceil, math.round o building functions >>> def function(argument): [header] >>> body statement >>> more body statements >>> return a variable February 11, 2016 modules and functions o you can use a function without understanding how the function works o authors of a function must make available the how-to-use information through docstrings and comments o rule 1 and 2 module starts with authorship comments and an explanation #module name #author(s) names (and netid) #last modified date “””a doctstring: a module to ____””” o rule 3. each function starts with a docstring “specification” short summary that states what the function returns (post condition) longer prose can be include which gives more useful info precondition: conditions that the argument must satisfy if the function is to work o know how to access functions: import create functions: def document functions: docstrings and comments procedures o procedures are functions that do not return values, they “do something” functions can call other functions o iterations, nesting, loops, random computations, recursion (will learn) simple graphics: o makewindow first: get a canvass from simplegraphics import* n=5 makewindow(n) window now exists: -5<=x<=5 and -5<=y<=5 makewindow (n, bgcolor=PURPLE) o this is an optional argument o overrides the default of white makewindow (n, bgcolor=ORANGE, labels=False) o disables axes’ labels o another optional argument o optional arguments don’t require a certain order, they’re like synonyms o module has data, 13 different colors o showwindow o drawrect must tell the program: the center of rectangle horizontal dimension vertical optional fill color o default is no color width of perimeter color of perimeter highlight rotation angle (theta=degree) x=0;y=0;L=5;W=3 Drawerct(x,y,L,W,fillcolor=magenta, edgewidth=6,theta=30) showwindow() o drawdisk must tell center radius in order to get the row of diminishing circles (use iterations of a math function) o drawstar also needs a center and radius o drawlineseg need to define the start and end points can define the color and width o drawtext tell: the location of text the string can tell: the color and size o drawTile tell the center, the radius, three colors of 3 objects in the tile (x,y,r,c1,c2,c3) color set of three number between 0 and 1, number represent the amount of [red, green, blue] a list of length three an application script uses procedures and functions defined above
Are you sure you want to buy this material for
You're already Subscribed!
Looks like you've already subscribed to StudySoup, you won't need to purchase another subscription to get this material. To access this material simply click 'View Full Document'