Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import time
- a =['3', '3', '*', '5', '+', '9', '-', '\n',
- '6', '2', '-', '3', '-', '8', '*', '\n',
- '10', '10', '*', '3', '+', '99', '-', '\n',
- '2', '4', '6', '*', '*', '4', '-', '\n',
- '7', '0', '-', '0', '*', '\n',
- '2', '9', '7', '/', '/', '\n',
- '9', '6', '3', '/', '2', '9', '-', '-', '+','\n',
- '4', '5', '/', '5', '5', '*', '5', '/','/','\n',
- '3', '5', '/', '5', 'not', '*']
- def main(x):
- stack = []
- temp = 0.0
- for i in a:
- if i.isnumeric():
- stack.append(float(i))
- elif i == '\n':
- print(stack[0])
- stack=[]
- time.sleep(0)
- else:
- if i == '*':
- temp = stack.pop()*stack.pop()
- if i == '/':
- try:
- temp = stack.pop(-2)/stack.pop()
- except ZeroDivisionError:
- print('Cant divide by 0')
- if i == '+':
- temp = stack.pop()+stack.pop()
- if i == '-':
- temp = stack.pop(-2)-stack.pop()
- # Have no idea how this is supposed to work :(
- if i == 'not':
- print("WHAT DOES THIS DO!")
- stack.append(temp)
- temp=0.0
- main(a)
Add Comment
Please, Sign In to add comment