Write a class called Height A Height represents a height in
Write a class called Height. A Height represents a height in feet and inches. It should have a constructor, __str__ and __repr__ methods, and an add method. The __str__ method should be written to follow this example:
The add should add 2 heights, and be written so that it is nondestrutive.
python 2.7.13
Solution
solution
class Height:
 height=0
 inches=0
 heightsum=0
 inchessum=0
   
 def __init__(self,height, inches):
 self.height = height
 self.inches = inches
 def displayHeight(self):
 print \"height : \", self.height, \", inches: \", self.inches
 def add(self,something):
 heightsum=self.height+something.height
 inchessum=self.inches+something.inches
 print \"height : \",heightsum, \", inches: \", inchessum
//creating the objects for the class
height1 = Height(2,2)
 height2=Height(3,3)
//height1.displayHeight()
 height1.add(height2)
output
height 5 inches 5

