Open the context
Choose the project folder and name the files or behavior involved.
Evaluate one through 100 postfix tokens using bounded integers and the operators +, -, * and //. Check negative floor division and reject division by zero, an incomplete stack or any intermediate magnitude above 10**18.
Choose the project folder and name the files or behavior involved.
Describe the input, expected output and boundaries that must stay intact.
Review the proposed edits and any commands before relying on their result.
Compare actual behavior with the expected result. If a check fails, investigate it before applying more changes.
def postfix_value(tokens):
tokens = tuple(tokens)
if not 1 <= len(tokens) <= 100:
raise ValueError("tokens.limit")
stack = []
for token in tokens:
if type(token) is int and abs(token) <= 1000000000:
stack.append(token)
continue
if type(token) is not str or token not in ("+", "-", "*", "//") or len(stack) < 2:
raise ValueError("token.invalid")
right, left = stack.pop(), stack.pop()
if token == "//" and right == 0:
raise ValueError("division.zero")
value = (left + right if token == "+" else left - right if token == "-" else left * right if token == "*" else left // right)
if abs(value) > 10**18:
raise ValueError("result.range")
stack.append(value)
if len(stack) != 1:
raise ValueError("stack.remainder")
return stack[0]The example is a starting point for a real project, not a claim that generated code is already tested. Adjust paths, dependencies and expected behavior to match your application.