


Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Community
Ask the community for help and clear up your study doubts
Discover the best universities in your country according to Docsity users
Free resources
Download our free guides on studying techniques, anxiety management strategies, and thesis advice from Docsity tutors
The third test for the cosc 235 course focusing on python programming concepts. It includes instructions for a class definition exercise, a method definition exercise, and an explanation of short-circuit evaluation. The document also covers the creation of a poolball class and the use of the find function.
Typology: Exams
1 / 4
This page cannot be seen from the preview
Don't miss anything!
class Button: "A button is a labeled rectangle in a window." def init(self, win, center, width, height, label): "Creates a rectangular button" w,h = width/2.0, height/2. x,y = center.getX(), center.getY() self.xmax, self.xmin = x+w, x-w self.ymax, self.ymin = y+h, y-h p1 = Point(self.xmin, self.ymin) p2 = Point(self.xmax, self.ymax) self.rect = Rectangle(p1,p2) self.rect.setFill('lightgray') self.rect.draw(win) self.label = Text(center, label) self.label.draw(win) self.deactivate() def clicked(self, p): "Returns true if button active and p is inside" return self.active and
self.xmin <= p.getX() <= self.xmax and
self.ymin <= p.getY() <= self.ymax def getLabel(self): "Returns the label string of this button." return self.label.getText() def activate(self): "Sets this button to 'active'." self.label.setFill('black') self.rect.setWidth(2) self.active = True def deactivate(self): "Sets this button to 'inactive'." self.label.setFill('darkgrey') self.rect.setWidth(1) self.active = False
PoolBall(number, color) Initialize an instance to the given number and color, where color is given by a string--for example, "yellow". getNumber() Returns the number of this ball. getColor() Returns the color of this ball. isSolid() Returns True if this ball has a solid color, False if striped. str() Return a string representation of this ball--for example, "1 ball [solid yellow]"
class PoolBall: def init(self, number, color): self.number = number self.color = color def getNumber(self): return self.number def getColor(self): return self.color def isSolid(self): return self.number <= 8 def str(self): if self.isSolid(): kind = "solid" else: kind = "striped" return "%d ball [%s %s]" % (self.number, kind, self.color) ball1 = PoolBall(1, "yellow") ball10 = PoolBall(10, "blue") print ball print ball
from graphics import * def main():
win = GraphWin("Test #3 Window", 600, 400)
The main module would come first and then calcAllowanceTotal and then displayTotal. The designer would identify getAge and then calcAllowance when considering an algorithm for calcAllowanceTotal. submitBtn = Button(win, Point(35, 25), 60, 40, “Submit”) submitBtn.activate()