Attributeerror: 'int' Object has no attribute 'value'

Asked

Viewed 690 times

-2

I can’t find the reason it gives Attributeerror: 'int' Object has no attribute 'value'

class DidaticaTech:
    def __int__(self, v=10, i=1):
        self.valor = v
        self.incremento = i
    def incrementa(self):
        self.valor = self.valor + self.incremento
a = DidaticaTech()
a.incremento()

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-70-c86fe0605456> in <module>
----> 1 a.incrementa()

AttributeError: 'int' object has no attribute 'incrementa'

2 answers

1


There are two errors in your code. The first error is that you are running the wrong method by calling incremento instead of incrementa.

The second error is that you created the constructor with the wrong name. The name should be __init__ instead of __int__. See below how your code should look.

class DidaticaTech:

    def __init__(self, v = 10, i = 1):
        self.valor = v
        self.incremento = i

    def incrementa(self):
        self.valor = self.valor + self.incremento

a = DidaticaTech()
a.incrementa()

0

You made a mistake calling your job.

The correct form would be:

a = DidaticaTech()
a.incrementa()

The variable incremento is also defined in its class and is an integer. That is why the error indicates that this variable is an integer and has no attribute incrementa

Another mistake you have is in function __init__, you stated as __int__

Browser other questions tagged

You are not signed in. Login or sign up in order to post.