Romini Posted March 16, 2015 at 06:28 PM Report Share #579566 Posted March 16, 2015 at 06:28 PM Bem eu tenho uma string do género a=("1234") e eu queria separar esses números de forma a somá-los, assim: 1+2+3+4 É algo do género: sum([int(x) for x in a]) mas eu nao queria usar esse método Como consigo fazer isso? Agradeço qualquer ajuda Link to comment Share on other sites More sharing options...
Solution lepolepo Posted March 16, 2015 at 10:20 PM Solution Report Share #579577 Posted March 16, 2015 at 10:20 PM s = "1234" soma = 0 for char in s: soma += int(char) 1 Report Link to comment Share on other sites More sharing options...
Romini Posted March 16, 2015 at 11:05 PM Author Report Share #579580 Posted March 16, 2015 at 11:05 PM Muito obrigada! é isso mesmo 😄 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now