Brak opisu

tt.py 519B

12345678910111213141516171819202122232425262728293031323334
  1. def toList(s):
  2. L = []
  3. for i in s:
  4. if i != '\n':
  5. L.append(i)
  6. return L
  7. def f(i,s,S = None):
  8. if not S:
  9. S = []
  10. if i == len(s):
  11. return S[0]
  12. a = s[i]
  13. if a.isdigit():
  14. S.append(a)
  15. return f(i+1,s,S)
  16. else:
  17. c = S.pop()
  18. d = S.pop()
  19. e = '%s%s%s'%(c,a,d)
  20. S.append(eval(e))
  21. return f(i+1,s,S)
  22. x = raw_input()
  23. s = ""
  24. while x != '=\n':
  25. s += x
  26. x = raw_input() + '\n'
  27. print f(0,toList(s))