Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8819863
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T05:28:08+00:00 2026-06-14T05:28:08+00:00

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

  • 0
from math import *
class GeometricObject():
     def __init__(self, color = "green", filled = True):
        self.color = color
        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()

Above is my code and the error I am getting I don’t understand, most of the code is direct from the book examples and adjusted to fit my program. What can I do to get this to work the way I need it to. This is for homework and I could really use some help to figure out what is wrong in my code.

This it not really an error but how can I get the GeometricObject color and filled properties to display after the other triangle information.

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 1(filled) or 0(not filled) for the triangle being filled: 1



A Triangle:  Triangle: side 1 = 3.0 side 2 = 4.0 side 3 = 5.0 <__main__.GeometricObject object at 0x000000000312EA20>
The area is:  6.0
The perimeter is:  12
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T05:28:09+00:00Added an answer on June 14, 2026 at 5:28 am

    The problem is that the instance variables in tri.__str__ are not being accessed properly.
    In order to access a variable belonging to an instance of the class, you need to preface the name with self.

    The variables names are also incorrect within the function: they should be __side1, __side2, and __side3.

    Replace your __str__ function with this, and it should work:

    def __str__(self):
        return "Triangle: " + "side 1 = " + str(self.__side1) +\
                "side 2 = " + str(self.__side2) + "side 3 = " + str(self.__side3)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

import math class Point: def __init__(self,x,y): self.x = x self.y = y def move(self,x,y):
import java.math.BigInteger; public class Rational extends Number implements Comparable { // Data fields for
import java.lang.Math; import java.awt.* public class Triangle implements Shape { java.awt.Point a; java.awt.Point b;
When using a DenseMatrix from Math .NET, and I want to access the second
Does (int)myDouble ever differ from (int)Math.Truncate(myDouble) ? Is there any reason I should prefer
I am trying to use GLSMultipleLinearRegression (from apache commons-math package) for multiple linear regression.
From http://msdn.microsoft.com/en-us/library/system.math.pow.aspx int value = 2; for (int power = 0; power <= 32;
I have a basic math question. I am trying to get a percentage from
When you have Math.floor(Math.random()*10)+1 its supposed to pick a random number between 1-10 from
I'm learning generics in Java from C++ and am confused how to do math

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.