Building Dice # turn correct pips on if value == 1: self.pip4.setFill(self.foreground) elif value == 2: self.pip1.setFill(self.foreground) self.pip7.setFill(self.foreground) elif value == 3: self.pip1.setFill(self.foreground) self.pip7.setFill(self.foreground) self.pip4.setFill(self.foreground) elif value == 4: self.pip1.setFill(self.foreground) self.pip3.setFill(self.foreground) self.pip5.setFill(self.foreground) self.pip7.setFill(self.foreground) elif value == 5: self.pip1.setFill(self.foreground) self.pip3.setFill(self.foreground) self.pip4.setFill(self.foreground) self.pip5.setFill(self.foreground) self.pip7.setFill(self.foreground) else: self.pip1.setFill(self.foreground) self.pip2.setFill(self.foreground) self.pip3.setFill(self.foreground) self.pip5.setFill(self.foreground) self.pip6.setFill(self.foreground) self.pip7.setFill(self.foreground) Python Programming, 3/e 102
View full slide show




Building Dice # turn correct pips on if value == 1: self.pip4.setFill(self.foreground) elif value == 2: self.pip1.setFill(self.foreground) self.pip7.setFill(self.foreground) elif value == 3: self.pip1.setFill(self.foreground) self.pip7.setFill(self.foreground) self.pip4.setFill(self.foreground) elif value == 4: self.pip1.setFill(self.foreground) self.pip3.setFill(self.foreground) self.pip5.setFill(self.foreground) self.pip7.setFill(self.foreground) elif value == 5: self.pip1.setFill(self.foreground) self.pip3.setFill(self.foreground) self.pip4.setFill(self.foreground) self.pip5.setFill(self.foreground) self.pip7.setFill(self.foreground) else: self.pip1.setFill(self.foreground) self.pip2.setFill(self.foreground) self.pip3.setFill(self.foreground) self.pip5.setFill(self.foreground) self.pip6.setFill(self.foreground) self.pip7.setFill(self.foreground) Python Programming, 2/e 101
View full slide show




Designing with Lists and Classes # dieview2.py # A widget for displaying the value of a die. # This version uses lists to simplify keeping track of pips. class DieView: """ DieView is a widget that displays a graphical representation of a standard six-sided die.""" def __init__(self, win, center, size): """Create a view of a die, e.g.: d1 = GDie(myWin, Point(40,50), 20) creates a die centered at (40,50) having sides of length 20.""" # first define some standard values self.win = win self.background = "white" # color of die face self.foreground = "black" # color of the pips self.psize = 0.1 * size # radius of each pip hsize = size / 2.0 # half of size offset = 0.6 * hsize # distance from center to outer pips # create a square for the face cx, cy = center.getX(), center.getY() p1 = Point(cx-hsize, cy-hsize) p2 = Point(cx+hsize, cy+hsize) rect = Rectangle(p1,p2) rect.draw(win) rect.setFill(self.background) # Create 7 circles for standard pip locations self.pips = [ self.__makePip(cx-offset, self.__makePip(cx-offset, self.__makePip(cx-offset, self.__makePip(cx, cy), self.__makePip(cx+offset, self.__makePip(cx+offset, self.__makePip(cx+offset, cy-offset), cy), cy+offset), cy-offset), cy), cy+offset) ] # Create a table for which pips are on for each value self.onTable = [ [], [3], [2,4], [2,3,4], [0,2,4,6], [0,2,3,4,6], [0,1,2,4,5,6] ] self.setValue(1) def __makePip(self, x, y): """Internal helper method to draw a pip at (x,y)""" pip = Circle(Point(x,y), self.psize) pip.setFill(self.background) pip.setOutline(self.background) pip.draw(self.win) return pip def setValue(self, value): """ Set this die to display value.""" # Turn all the pips off for pip in self.pips: pip.setFill(self.background) # Turn the appropriate pips back on for i in self.onTable[value]: self.pips[i].setFill(self.foreground) Python Programming, 1/e 63
View full slide show




Self-affirming statement John Madden: “There isn’t a person in this stadium who’s left yet.”
View full slide show




Developing a GUI class GraphicsInterface: def __init__(self): self.win = GraphWin("Dice Poker", 600, 400) self.win.setBackground("green3") banner = Text(Point(300,30), "Python Poker Parlor") banner.setSize(24) banner.setFill("yellow2") banner.setStyle("bold") banner.draw(self.win) self.msg = Text(Point(300,380), "Welcome to the dice table.") self.msg.setSize(18) self.msg.draw(self.win) self.createDice(Point(300,100), 75) self.buttons = [] self.addDiceButtons(Point(300,170), 75, 30) b = Button(self.win, Point(300, 230), 400, 40, "Roll Dice") self.buttons.append(b) b = Button(self.win, Point(300, 280), 150, 40, "Score") self.buttons.append(b) b = Button(self.win, Point(570,375), 40, 30, "Quit") self.buttons.append(b) self.money = Text(Point(300,325), "$100") self.money.setSize(18) self.money.draw(self.win) Python Programming, 2/e 113
View full slide show




Developing a GUI class GraphicsInterface: def __init__(self): self.win = GraphWin("Dice Poker", 600, 400) self.win.setBackground("green3") banner = Text(Point(300,30), "Python Poker Parlor") banner.setSize(24) banner.setFill("yellow2") banner.setStyle("bold") banner.draw(self.win) self.msg = Text(Point(300,380), "Welcome to the dice table.") self.msg.setSize(18) self.msg.draw(self.win) self.createDice(Point(300,100), 75) self.buttons = [] self.addDiceButtons(Point(300,170), 75, 30) b = Button(self.win, Point(300, 230), 400, 40, "Roll Dice") self.buttons.append(b) b = Button(self.win, Point(300, 280), 150, 40, "Score") self.buttons.append(b) b = Button(self.win, Point(570,375), 40, 30, "Quit") self.buttons.append(b) self.money = Text(Point(300,325), "$100") self.money.setSize(18) self.money.draw(self.win) Python Programming, 1/e 113
View full slide show




Building Dice def __makePip(self, x, y): """Internal helper method to draw a pip at (x,y)""" pip = Circle(Point(x,y), self.psize) pip.setFill(self.background) pip.setOutline(self.background) pip.draw(self.win) return pip def setValue(self, value): """ Set this die to display value.""" # turn all pips off self.pip1.setFill(self.background) self.pip2.setFill(self.background) self.pip3.setFill(self.background) self.pip4.setFill(self.background) self.pip5.setFill(self.background) self.pip6.setFill(self.background) self.pip7.setFill(self.background) Python Programming, 3/e 101
View full slide show




Building Dice def __makePip(self, x, y): """Internal helper method to draw a pip at (x,y)""" pip = Circle(Point(x,y), self.psize) pip.setFill(self.background) pip.setOutline(self.background) pip.draw(self.win) return pip def setValue(self, value): """ Set this die to display value.""" # turn all pips off self.pip1.setFill(self.background) self.pip2.setFill(self.background) self.pip3.setFill(self.background) self.pip4.setFill(self.background) self.pip5.setFill(self.background) self.pip6.setFill(self.background) self.pip7.setFill(self.background) Python Programming, 2/e 100
View full slide show




Site Plan Showing Proposed Modifications for Approval Adaptive reuse of baseball stadium Enhanced Softball Improvements Elimination of Pond & replace with green space New site for Tennis Stadium Reduction of parking at proposed tennis stadium Potential Modifications: Enhanced softball improvements (8D), adaptive reuse of baseball stadium (5A), new site for tennis stadium (6A), elimination of pond & replacing with green space (9), & reduction of parking at proposed tennis stadium. 17
View full slide show




Pronouns and antecedents should “agree” in case, number, person, and gender. Personal pronouns, nominative case Possessive pronouns Person/num ber Singular Plural Person/num ber Singular Plural 1st person I we 1st person my, mine our, ours 2nd person you you 2nd person your, yours your, yours 3rd person his, her, hers, its their, theirs 3rd person he, she, they Subject: I think, you did, it we write, they are Personal pronouns, objective case Reflexive/Intensive pronouns Person/num ber Singular Plural Person/num ber Singula r Plural 1st person me us 1st person myself ourselves 2nd person you you 2nd person yourself yourselves 3rd person himself, herself, itself themselve s 3rd person him, her, them Object: You told me. I gave it you the answer. The book belongs to her. I can’t hear you.
View full slide show




Pronoun - Used in place of one or more nouns Antecedent - word to which pronoun refers Personal pronouns, nominative case Possessive pronouns Person/num ber Singular Plural Person/num ber Singular Plural 1st person I we 1st person my, mine our, ours 2nd person you you 2nd person 3rd person he, she, it they your, yours your, yours 3rd person his, her, hers, its their, theirs Personal pronouns, objective case Reflexive/Intensive pronouns Person/num ber Singular Plural Person/num ber Singula r Plural 1st person me us 1st person myself ourselves 2nd person you you 2nd person yourself yourselves 3rd person him, her, it them 3rd person himself, herself, itself themselve s
View full slide show




Total Order Plans: Partial Order Plans: Start Left Sock Right Sock Left Sock on Right Sock on Left Shoe Right Shoe Left Shoe on Start Start Start Start Start Start Right Sock Right Sock Left Sock Left Sock Right Sock Left Sock Left Sock Left Sock Right Sock Right Sock Right Shoe Right Shoe Left Shoe Left Sock Right Shoe Left Sock Left Shoe Right Shoe Left Shoe Right Sock Right Shoe on Finish Finish Finish Left Shoe Finish Right Shoe Left Shoe Finish Finish Right Shoe Finish
View full slide show




Building Dice # create a square for the face cx, cy = center.getX(), center.getY() p1 = Point(cx-hsize, cy-hsize) p2 = Point(cx+hsize, cy+hsize) rect = Rectangle(p1,p2) rect.draw(win) rect.setFill(self.background) # Create 7 circles for standard pip locations self.pip1 = self.__makePip(cx-offset, cy-offset) self.pip2 = self.__makePip(cx-offset, cy) self.pip3 = self.__makePip(cx-offset, cy+offset) self.pip4 = self.__makePip(cx, cy) self.pip5 = self.__makePip(cx+offset, cy-offset) self.pip6 = self.__makePip(cx+offset, cy) self.pip7 = self.__makePip(cx+offset, cy+offset) self.setValue(1) Python Programming, 3/e 100
View full slide show




class Box5(Box): def __init__(self,l=1,w=1): self.length = l self.width = w self._color = None @property def area(self): return self.length * self.width @area.setter def area(self, val=1): self.length = self.width = math.sqrt(val) @property def color(self): return self._color @color.setter def color(self, val): self._color = val @color.deleter def color(self): del self._color Decorated Boxes
View full slide show




///////////////////////////////////////////// // Class implementation file: Person.cpp // // // // This program file contains the actual // // implementations of the member functions // // of the person class defined in the // // Person.h header file. // ///////////////////////////////////////////// // The initializing constructor sets // // the three data members of *this to // // the parameterized string values. // person::person(string fnm, string ad1, string ad2) { fullName = fnm; firstAddressLine = ad1; secondAddressLine = ad2; } #include "Person.h" #include // The height member function returns // the number of output lines that are // needed to output the person *this. int person::height() { return NBR_OF_OUTPUT_LINES; } using namespace std; // The default constructor sets the three // // data members of *this to empty strings. // person::person() { fullName = firstAddressLine = secondAddressLine = ""; } // The copy constructor sets the three data // members of *this to the corresponding data // member values of the parameterized person. person::person(const person &p) { fullName = p.fullName; firstAddressLine = p.firstAddressLine; secondAddressLine = p.secondAddressLine; } CS 240 // // // // // // // The getLineNumber member function returns // // the appropriate addressing line, depending // // upon the value of the integer parameter. // string person::getLineNumber(int i) { switch (i) { case 3: return secondAddressLine; break; case 2: return firstAddressLine; break; default: return fullName; break; } } 43
View full slide show