data_structures.stacks.prefix_evaluation

Python3 program to evaluate a prefix expression.

Attributes

calc

test_expression

Functions

evaluate(expression)

Evaluate a given expression in prefix notation.

is_operand(c)

Return True if the given char c is an operand, e.g. it is a number

Module Contents

data_structures.stacks.prefix_evaluation.evaluate(expression)

Evaluate a given expression in prefix notation. Asserts that the given expression is valid.

>>> evaluate("+ 9 * 2 6")
21
>>> evaluate("/ * 10 2 + 4 1 ")
4.0
data_structures.stacks.prefix_evaluation.is_operand(c)

Return True if the given char c is an operand, e.g. it is a number

>>> is_operand("1")
True
>>> is_operand("+")
False
data_structures.stacks.prefix_evaluation.calc
data_structures.stacks.prefix_evaluation.test_expression = '+ 9 * 2 6'