fork download
  1. def calcs(s):
  2. s = '+'+s
  3. out = 0
  4. i = 0
  5. one = act = ''
  6. while i <=len(s)-1:
  7. if s[i] == '+':
  8. act = '+'
  9. i+=1
  10. continue
  11. elif s[i] == '-':
  12. act = '-'
  13. i+=1
  14. continue
  15. else:
  16. while s[i].isdigit():
  17. one += s[i]
  18. i+=1
  19. if i > len(s)-1:
  20. break
  21. if act == '+':
  22. out += int(one)
  23. else:
  24. out-= int(one)
  25. one = ''
  26. return out
  27. print(calcs('1+2+3-2-1+0+13-16'))
Success #stdin #stdout 0.02s 8736KB
stdin
Standard input is empty
stdout
0