Python actually has a way to finish the program execution by doing:
sys.exit(0)
Assuming you previously included the library sys:
import sys
In your case it would look like this:
import sys # importação aqui
def soma():
n1=int(input('digite um numero'))
n2=int(input('digite outro'))
soma = n1+n2
print('A soma de {} e {} é {}'.format(n1,n2,soma))
system.exit(0) # terminar o programa aqui
This exit is made at the expense of an exception System.Exit, as you can see in the documentation, which allows the program to perform cleaning actions. The parameter 0 past indicates that the program ended successfully.
Note:
Although it works this way the best would be to change the program flow, as the @escapistabr response showed, because it is more clear to see how the program follows, and it ends up being simpler than this.
Oh yes rs, vdd. I didn’t even care. .
– Aprendiz