Python Programming: An Introduction To Computer Science: Defining Classes
Python Programming: An Introduction To Computer Science: Defining Classes
Python Programming: An Introduction To Computer Science: Defining Classes
An Introduction To
Computer Science
Chapter 10
Defining Classes
def main():
angle = eval(input("Enter the launch angle (in degrees): "))
vel = eval(input("Enter the initial velocity (in meters/sec): "))
h0 = eval(input("Enter the initial height (in meters): "))
time = eval(input("Enter the time interval between position calculations: "))
main()
class MSDie:
def roll(self):
self.value = randrange(1, self.sides+1)
def getValue(self):
return self.value
def getX(self):
return self.xpos
def getQPoints(self):
return self.qpoints
def gpa(self):
return self.qpoints/self.hours
def makeStudent(infoStr):
name, hours, qpoints = infoStr.split("\t")
return Student(name, hours, qpoints)
random(...)
random() -> x in the interval [0, 1).
"""projectile.py
Provides a simple class for modeling the flight of projectiles."""
class Projectile:
def getY(self):
"Returns the y position (height) of this projectile."
return self.ypos
def getX(self):
"Returns the x position (distance) of this projectile."
return self.xpos
class DieView:
""" DieView is a widget that displays a graphical representation
of a standard six-sided die."""
self.setValue(1)
def main():
# close up shop
win.close()
main()