Last answered:

14 Mar 2022

Posted on:

14 Mar 2022

0

Resolved: Error 'float' object is not callable when using the display_balance()

Hi! So, my code is here. I've used the exact same commands as instructed, but I've changed their names to Portuguese. But everything else is the same. Here it goes:

class ccNu(object):
    ''' Contas correntes dos clientes do NuBank.'''
    def __init__(self,saldo=0.0):
        self.saldo = saldo

def saldo(self):
        print(f"O seu saldo é de {self.saldo}.")

def deposit(self):
        quantia = float(input('Quanto você gostaria de depositar? \n > '))
        self.saldo += quantia
        print(f'O saldo agora é de {self.saldo}.')

def sacar(self):
        saque = float(input("Quanto você gostaria de sacar? \n > "))
        if saque > self.saldo:
            print(f'Você não tem saldo o suficiente. Seu saldo é {self.saldo}.')
        else:
            self.saldo -= saque
            print(f"Saque computado. O saldo agora é de {self.saldo}.")

Joao = ccNu(650.0)
Joao.deposit()
Joao.sacar()
Joao.saldo()

If I run Joao.deposit() or Joao.sacar() it runs fine.
But if I try Joao.saldo() I get this error:
Joao.saldo()
Traceback (most recent call last):

File "C:\Users\jaff_\AppData\Local\Temp/ipykernel_5332/1860965932.py", line 1, in <module>
    Joao.saldo()

TypeError: 'float' object is not callable

Any ideas?

1 answers ( 1 marked as helpful)
Instructor
Posted on:

14 Mar 2022

0

Hey João,

Thank you for your question!

Notice that the function saldo() bears the same name as the variable saldo. Just change the name of the function (or the variable) to something else and everything should work as expected.

Kind regards,
365 Hristina

Submit an answer