You should add a __repr__
method to your class. For example:
class Rectangle:
def __init__(self, x, y, w, h):
self.x = x
self.y = y
self.w = w
self.h = h
def expand(self, expand_num): # Method to expand/shrink the original rectangle
return Rectangle(self.x - expand_num, self.y - expand_num, self.w + expand_num * 2, self.h + expand_num * 2)
def __repr__(self):
return "Rectangle("+str(self.x)+", " + str(self.y)+ ", " + str(self.w) + ", " + str(self.h) + ")"
r_orig = Rectangle(30,40,100,110)
try_expand = 0
while try_expand != "N" and try_expand !="n":
input_num = input("How much would you like to expand or shrink r by? ")
expand_num = int(input_num)
print("Rectangle r expanded/shrunk = ", r_orig.expand(expand_num))
try_expand = input("Would you like to try expanding or shrinking again? Y or N ")
print("")
see http://docs.python.org/2/reference/datamodel.html#object.__repr__