main.py - from stack import Stack def loadExpressions():...

This preview shows page 1 - 2 out of 2 pages.

from stack import Stackdef loadExpressions():"""loads epressions"""expressions = []with open("Data.txt", "r") as txt_file:for row in txt_file:expressions.append(row.strip())return expressionsOPERATORS = ['+', '-', '*', '/', '(', ')', '^']PRIORITY = {'+':1, '-':1, '*':2, '/':2, '^':3}def in2post(exp):"""infix to postfix calc"""exp = "("+exp+")"stack = Stack()output = ''for ch in exp:if ch not in OPERATORS:output+= chelif ch=='(':stack.push(ch)elif ch==')':while stack and stack.items[-1]!= '(':output+=' ' + stack.pop()new_func(stack)stack.pop()else:while stack and stack.items[-1]!='(' andPRIORITY[ch]<=PRIORITY[stack.items[-1]]:output+=' ' + stack.pop()stack.push(ch)if stack.items[-1] ==')':
End of preview. Want to read all 2 pages?

Upload your study docs or become a

Course Hero member to access this document

Term
Spring
Professor
DanielC.Gale
Tags
Derivative, Reverse Polish notation, stack import Stack

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture