Click here to Skip to main content
15,880,796 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
(please note I need to use two classes and the __init__ and __str__)I need to print out the values of my code using str but it's not printing out I am confused because I feel like I added all the attributes correctly and it gets all the values but just doesn't print out what I need it to print out. What I am trying to do is find the area and circumference of a circle using classes, init and str with the radius as 3 and pi as 3.14. I really need help and if you know any way to do this it would really help

Here is the code:
class Given():
    def __init__(self):
        self.radius = 3
        self.pi = 3.14
        self.stringforradius = str(self.radius)
        self.stringforpi = str(self.pi)
def __str__(self):
    return("radius = {}, pi = {}, The area of the circle is {},radius = {}, pi = {}, The circumference of the circle is {} ".format (self.stringforradius, self.stringforpi, self.getcircumference,self.stringforradius, self.stringforpi, self.getarea))
  
class area(Given):
    def squared(self):
        self.square = self.radius * self.radius  
    
    def area(self):
        self.ar = self.pi * self.square
        self.getarea = str(self.ar)



class circumference(Given):
    def cir(self):
        self.cir1 = 2 * self.pi * self.radius
        self.getcircumference = str(self.cir1)

gettingtotal = area()
gettingtotal.squared()
gettingtotal.area()
gettingtotall = circumference()
gettingtotall.cir()
print(gettingtotal.__str__())
print(gettingtotall.__str__())


What I have tried:

I have tried many different ways to fix my variables but this is as close as I got
Posted
Updated 13-Feb-22 11:33am

1 solution

This is the same question you asked yesterday: Python: I need to get my values to print using __str__ but I dont know how[^]
And the solution is the same: read up on __str__ using the link you were given then, and think about what you are being asked to do.
 
Share this answer
 
Comments
LH Alpha 13-Feb-22 17:36pm    
I need help because those variables in the __str__ don't mean anything in that context because it's not under area nor circumference and Idk how to fix it.
I also said I needed help because I still don't understand and this doesn't help if I read it and still don't understand. I made improvements from last time too

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900