Forums: » Register « |  Free Tools |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support |

New Free Tools on Dev Shed!

#1
November 13th, 2012, 11:17 PM
 crazyjdog
Registered User

Join Date: Nov 2012
Posts: 7
Time spent in forums: 2 h 17 sec
Reputation Power: 0

This is my output and below is my code. How do I get the color and filled property to display rather than this
<__main__.GeometricObject object at 0x000000000319FEF0> at the end of my output?
Code:
```Enter a value for side 1: 3
Now enter a value for side 2: 4
Now enter a value for side 3: 5
Enter the color of the triangle: blue
Enter true(filled) or false(not filled) for the triangle being filled: true

A Triangle:  Triangle: side 1 = 3.0 side 2 = 4.0 side 3 = 5.0 <__main__.GeometricObject object at 0x000000000319FEF0>
The area is:  6.0
The perimeter is:  12```

Code:
```from math import *
class GeometricObject():
def __init__(self, color = "green", filled = True):
self.color = color
self.filled = filled

def getColor(self):
return self.color

def setColor(self, color):
self.color = color

def getFilled(self):
return self.filled

def setFilled(self, filled):
self.filled = filled

def __str__(self):
return "color: " + self.__color + \
" and filled: " + str(self.__filled)

class Triangle(GeometricObject):
def __init__(self, side1 = 1, side2 = 1, side3 = 1):
super().__init__()
self.side1 = float(side1)
self.side2 = float(side2)
self.side3 = float(side3)

def getArea(self):
return self.area

def setArea(self, side1, side2, side3):
s = (side1 + side2 + side3)/2
area = sqrt(s*(s-side1)*(s-side2)*(s-side3))
self.area = area

def getPerimeter(self):
return self.perimeter

def setPerimeter(self, side1, side2, side3):
perimeter = side1 + side2 + side3
self.perimeter = perimeter

def __str__(self):
return "Triangle: " + "side 1 = " + str(self.side1)+ \
" " + "side 2 = " + str(self.side2) + " " + \
"side 3 = " + str(self.side3)

def main():
side1 = eval(input("Enter a value for side 1: "))
side2 = eval(input("Now enter a value for side 2: "))
side3 = eval(input("Now enter a value for side 3: "))
color = input("Enter the color of the triangle: ")
filled = input("Enter true(filled) or false(not filled) " + \
"for the triangle being filled: ")

go = GeometricObject(color, filled)
tri = Triangle(side1, side2, side3)
tri.setArea(side1, side2, side3)
tri.setPerimeter(side1, side2, side3)

print("\n\n")
print("A Triangle: ", tri.__str__(), go.__str__())
print("The area is: ", tri.getArea())
print("The perimeter is: ", tri.getPerimeter())

main()```

Last edited by crazyjdog : November 13th, 2012 at 11:46 PM. Reason: more descriptive title

#2
November 13th, 2012, 11:54 PM
 KING-OLE
Registered User

Join Date: Nov 2012
Location: Texas
Posts: 24
Time spent in forums: 5 h 54 m 45 sec
Reputation Power: 0
Did not do a complete study on your code, but did notice that you use true and false instead of True and False.

First letter has to be capitalized.

EDIT: Tried to run the program, and can see that's not the issue you're asking about. Sorry!

#3
November 14th, 2012, 12:01 AM
 crazyjdog
Registered User

Join Date: Nov 2012
Posts: 7
Time spent in forums: 2 h 17 sec
Reputation Power: 0
I tried with "True" instead of "true" and I still get this
<__main__.GeometricObject object at 0x000000000319FEF0> as the second part of my output.
The thing is I don't know what is missing to make "color: blue and filled: True" to display instead of what is being displayed.

#4
November 14th, 2012, 02:34 PM
 b49P23TIvg
Contributing User

Join Date: Aug 2011
Posts: 4,165
Time spent in forums: 1 Month 3 Weeks 2 Days 9 h 34 m 16 sec
Reputation Power: 455
The problem is, and it took me a while to see, is that your indentation is screwy. You defined a batch of functions within the GeometricObject.__init__ method scope.
Code:
```from math import *
class GeometricObject():
def __init__(self, color = "green", filled = True):
self.color = color
self.filled = filled

def getColor(self):
return self.color
#...```

What is __filled ?
What is __color ?

Instead of obj.__str__() use str(obj) . That's the main point of the methods with special names.

What if I provide edge lengths of 1 1 and 3 ?
__________________
[code]Code tags[/code] are essential for python code!

#5
November 15th, 2012, 12:05 AM
 crazyjdog
Registered User

Join Date: Nov 2012
Posts: 7
Time spent in forums: 2 h 17 sec
Reputation Power: 0
I was able to get it to work, thanks for the help!

 Viewing: Dev Shed Forums > Programming Languages > Python Programming > Not getting desired display