[Tutor] OOP class declaration question

Cameron Stoner wolf_binary@hotmail.com
Wed Jan 8 19:20:02 2003


Hi all,

Recently I made a class that I found out wouldn't work properly unless all 
the variables were filled with something.  My question is why do you have to 
have all the fields filled with something? Is it because you can't make an 
object of something without knowing what each part is soposed to be?  I 
thought python could allow for variable declaration on the fly and you 
didn't have to worry about what type of data it was sopposed to hold.

Thanks,

-Cameron


Here is the code:

class mobileSuit:
  def __init__(self,lArm, rArm, head, lLeg, rLeg, back, maxHealth):
    self.leftArmHealth = lArm
    self.rightArmHealth = rArm
    self.headHealth = head
    self.leftLegHealth = lLeg
    self.rightLegHealth = rLeg
    self.backHealth = back
    self.maxHealth = maxHealth
    self.healthPercent
    self.actualHealth


  #request overall health
  def overallHealth(self, report):

    #determine actualHealth
    self.actualHealth = (self.leftArmHealth + self.rightArmHealth +
     self.headHealth + self.leftLegHealth + self.rightLegHealth +
     self.backHealth) / 6


    #find percent of health
    self.healthPercent = (self.actualHealth / self.maxHealth) * 100

    # report the status with a print else return the result
    if report == 1:
      print "The MS health is: ", self.healthPercent
    else:
      return self.healthPercent



testSuit = mobileSuit(6,6,6,6,6,6,6)



_________________________________________________________________
Help STOP SPAM: Try the new MSN 8 and get 2 months FREE* 
http://join.msn.com/?page=features/junkmail