1
Code 1, if variable num is 1 or 2, for example when the conv()
is called again and I choose option 3 to exit then wheel the print
I hope I have been helpful (: but the program does not close, only the next time I choose option 3.
In code 2 the problem does not occur, everything works correctly, I wondered 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()
This code has some problems, just solving it doesn’t mean it will be right. Working is different than being right. To fix it, you’d have to rewrite the code. I don’t even know if I can explain why I would need to have a knowledge that I don’t seem to have yet.
– Maniero