OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

AttributeError: [obj_name] object has no attribute [attribute name which im passing] [closed]

  • Thread starter Thread starter A2514
  • Start date Start date
A

A2514

Guest
Code:
class Circle():
    pi = 3.14
    def __inti__(self, radius = 1):
        self.radius = radius
        self.area = radius*radius*self.pi
    
    def get_circumference(self):
        return self.radius*2*self.pi
    
my_circle = Circle()
print(my_circle.radius)

error:

Code:
Traceback (most recent call last):
  File "c:\Users\username\Desktop\py\classes.py", line 31, in <module>
    print(my_circle.radius)
          ^^^^^^^^^^^^^^^^
AttributeError: 'Circle' object has no attribute 'radius'

Im learning classes in python, and am not able radius of the circle. I was expecting to get radius printed.
<pre><code>class Circle():
pi = 3.14
def __inti__(self, radius = 1):
self.radius = radius
self.area = radius*radius*self.pi

def get_circumference(self):
return self.radius*2*self.pi

my_circle = Circle()
print(my_circle.radius)
</code></pre>
<p>error:</p>
<pre><code>Traceback (most recent call last):
File "c:\Users\username\Desktop\py\classes.py", line 31, in <module>
print(my_circle.radius)
^^^^^^^^^^^^^^^^
AttributeError: 'Circle' object has no attribute 'radius'
</code></pre>
<p>Im learning classes in python, and am not able radius of the circle. I was expecting to get radius printed.</p>
 

Latest posts

S
Replies
0
Views
1
Safwan Aipuram
S
Top