MCPcopy Index your code
hub / github.com/ndleah/python-mini-project / calculate_postfix

Function calculate_postfix

infix_postfix_calculator/main.py:52–72  ·  view source on GitHub ↗
(postfix)

Source from the content-addressed store, hash-verified

50
51
52def calculate_postfix(postfix):
53 ret = ""
54 s = []
55 postfix = postfix.strip()
56 postfix_arr = postfix.split(' ')
57 for token in postfix_arr:
58 if token in ["+", "-", "*", "/"]:
59 b = s.pop()
60 a = s.pop()
61 if token == "+":
62 s.append(a + b)
63 elif token == "-":
64 s.append(a - b)
65 elif token == "*":
66 s.append(a * b)
67 elif token == "/":
68 s.append(a / b)
69 else:
70 s.append(float(token))
71 ret = str(s.pop())
72 return ret
73
74from tkinter import *
75

Callers 1

calculateFunction · 0.85

Calls 3

stripMethod · 0.80
splitMethod · 0.80
popMethod · 0.45

Tested by

no test coverage detected