Code 1, if variable num is 1 or 2 for example, when conv()
is called again and I choose option 3 to exit then it runs print
I hope I have been useful (: program does not close, only the next time I choose option 3.
In code 2 the problem does not occur, everything works correctly, I wanted to know what would be the difference that makes it occur.
Code 1
def conv():
print("\nEscolha umas das duas opcoes abaixo!\n[1] Metro para Centimetro\n[2] Centimetro para Metro\n[3] Sair")
num = input("")
if num == 1:
met = input("\nDigite o metro\n")
result = float(met)*100
print("\nA resposta e >> " + str(result) + " centimetros\n\n")
conv()
if num == 2:
cen = input("\nDigite o centimetro\n")
result = float(cen)/100
print("\nA resposta e >> " + str(result) + " metros\n\n")
conv()
if num == 3:
print("\nEspero ter sido util (:\n\n")
sair()
else:
print("\nOpcao invalida\n\n")
conv()
def sair():
exit
conv()
Code 2
def conv():
print("\nEscolha umas das duas opcoes abaixo!\n[1] Metro para Centimetro\n[2] Centimetro para Metro\n[3] Sair")
num = input("")
if num == 1:
met = input("\nDigite o metro\n")
result = float(met)*100
print("\nA resposta e >> " + str(result) + " centimetros\n\n")
conv()
else:
if num == 2:
cen = input("\nDigite o centimetro\n")
result = float(cen)/100
print("\nA resposta e >> " + str(result) + " metros\n\n")
conv()
else:
if num == 3:
print("\nEspero ter sido util (:\n\n")
sair()
else:
print("\nOpcao invalida\n\n")
conv()
def sair():
exit
conv()