Python Forum

Full Version: Help with Code
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello everyone, need some help with my code below. The objective of the code is to take input for 3 sides of a triangle from the user and print the area. I am trying to do it using classes but the area keeps showing as zero. Could you please let me know what in the code needs to be fixed

class area_input:
    def __init__(self):
        self.a = int(input("enter side 1"))
        self.b = int(input("enter side 2"))
        self.c = int(input("enter side 3"))

class area_cal(area_input):
    def __init__(self,*args):
        super(area_cal,self).__init__(*args)
        
    
    def __str__(self):
        self.s = (self.a+self.b+self.c)/2
        self.area = (self.s*(self.s-self.a)*(self.s-self.b)*(self.s-self.c))**0.5
        return "Area is %f" %(self.area)
The part that calculates the area works just fine; however, there is an error in line 9 that keeps the code from running. Obviously, you modified the code for posting and removed the original error when you did. My guess is that the problem was in the original __init__ function on line 2 that you changed for posting, or the error was somewhere in the code you cut out.