Guest User

Untitled

a guest
Mar 22nd, 2018
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. import time
  2.  
  3. a =['3', '3', '*', '5', '+', '9', '-', '\n',
  4. '6', '2', '-', '3', '-', '8', '*', '\n',
  5. '10', '10', '*', '3', '+', '99', '-', '\n',
  6. '2', '4', '6', '*', '*', '4', '-', '\n',
  7. '7', '0', '-', '0', '*', '\n',
  8. '2', '9', '7', '/', '/', '\n',
  9. '9', '6', '3', '/', '2', '9', '-', '-', '+','\n',
  10. '4', '5', '/', '5', '5', '*', '5', '/','/','\n',
  11. '3', '5', '/', '5', 'not', '*']
  12.  
  13.  
  14. def main(x):
  15. stack = []
  16. temp = 0.0
  17. for i in a:
  18. if i.isnumeric():
  19. stack.append(float(i))
  20. elif i == '\n':
  21. print(stack[0])
  22. stack=[]
  23. time.sleep(0)
  24. else:
  25. if i == '*':
  26. temp = stack.pop()*stack.pop()
  27. if i == '/':
  28. try:
  29. temp = stack.pop(-2)/stack.pop()
  30. except ZeroDivisionError:
  31. print('Cant divide by 0')
  32. if i == '+':
  33. temp = stack.pop()+stack.pop()
  34. if i == '-':
  35. temp = stack.pop(-2)-stack.pop()
  36. # Have no idea how this is supposed to work :(
  37. if i == 'not':
  38. print("WHAT DOES THIS DO!")
  39. stack.append(temp)
  40. temp=0.0
  41.  
  42.  
  43.  
  44. main(a)
Add Comment
Please, Sign In to add comment