1
This my code simulates banking operations using functions, but I am not able to return the function values, when I Seto the value of the Return in a variable it calls the whole function. In the program when I call the function 'balance', it returns me the function 'deposit' and not the value of 'amount'.
Any guidance? How can I do that? There’s a better way?
def deposito(dep):
clear()
montante=0.0
dep=0.0
dep=float(input("Quantia a ser depositada:"))
clear()
if (dep > 0):
print (" |",montante)
print ("+|",dep)
montante=montante+dep
print ("____________")
print (" |",montante,"\n\n")
else:
print("Quantia inválida")
voltar()
return montante
def saldo():
saldo=deposito()
print("O seu saldo é:", saldo())
def main():
op=0
while(op != range(0,4,1)):
clear()
print("Qual tipo de operação deseja realizar?\n")
print ("[1]Saldo")
print ("[2]Depósito")
print ("[3]Saque")
print ("[0]Sair\n")
op=str(input(""))
if(op == "1"):
saldo()
elif(op == "2"):
deposito()
elif(op == "3"):
saque()
elif(op == "0"):
exit
else:
clear()
print("Operação inválida")
time.sleep(1)
I think the code is having some problems in formatting. At least on my mobile the function
deposito
and your first command are at the same indentation level– Jefferson Quesado
If you want to know
op
is not in the range that varies [0.4), its condition of thewhile
of functionmain
isn’t doing that– Jefferson Quesado
saldo
is in infinite recursion? Actually I can’t predict the behavior of Python in this case, although I think it will tell you that the parameterdep
has no standard value, or thatfloat
is not executable– Jefferson Quesado
Reinforcing what @Jeffersonquesado said, confirm that the identation of the code here in the question is the same as it has. If it is not correct.
– Isac
Dei rollback in the edition that applied indentation, taking into account that it, if not done correctly, can affect the functioning of python code.
– user28595
Done the code identation correction here, in the program is correct.
– Yan Teixeira