Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- stack = []
- operations = {
- '+': lambda a, b: a + b,
- '-': lambda a, b: a - b,
- '*': lambda a, b: a * b,
- '/': lambda a, b: a / b
- }
- def calculate(a, b, sign):
- return operations.get(sign)(a, b)
- def main():
- data = input("Dej mnie równanie: ").split()
- for item in data:
- if item in operations.keys():
- b = stack.pop()
- a = stack.pop()
- stack.append(calculate(a, b, item))
- else:
- try:
- stack.append(float(item))
- except ValueError:
- print("Co to za guwno")
- return
- print(stack.pop())
- main()
Advertisement
Add Comment
Please, Sign In to add comment