QUESTION

Text
Image

A2B2 (10 marks) Develop a Stack-Based Application of evaluating Postfix Arithmetic Expressions (PAE), with the given Python file A2B2.py
I want to use binaryOpn and evaluatePAE, thank you very much At least one line of simple comment for each extra operation required Sample codes of file $\mathbf{A}$ 2B2 . py, for reference only (May contain bugs). \# A2B2. py, for IDSA A2 \# .. from Stack import stack class PostFixAE: \#* Assume valid PAE in inList def_init_(self, inList): \# constructor \# A2B2.py, for IDSA A2 \# .. from Stack import Stack class PostFixAE: \# * Assume valid PAE in inList def__init__(self, inList): \# constructor
A2B2 (10 marks) Develop a Stack-Based Application of evaluating Postfix Arithmetic Expressions (PAE), with the given Python file A2B2 . py. - Suppose we are defining our OWN binary arithmetic operators with string symbols below: \begin{tabular}{|l|l|} \hline Operator symbols (Strings) & Description \\ \hline 'ad' & Addition, as Python + \\ \hline 'su' & Subtraction, as Python - \\ \hline ' $\mathrm{mu}$ ' & Multiply, as Python * \\ \hline \end{tabular} - Write a Python program to evaluate postfix Arithmetic Expressions, with the given Stack: ○ Define a Python PostFixAE class in file A2B2 . py, with given Stack class (in file Stack . py), to evaluate Postfix Arithmetic Expression (PAE) using the algorithm in our lecture note (slide 21): - Examples of valid PAE (Postfix Arithmetic Expression) stored in a Python list as input PAR - Input Python List $\left[9,9,7, ' \mathbf{s u}^{\prime}, ' \mathrm{mu} '\right]$ as input PAE 997-* - Input Python List $[9,7$, 'su ' , 2, 3, 'mu ' ' 'ad ' ] as input PAE 97-23*+ - Operations (methods of the class) to be implemented by Students: * ONLY access the interface (methods) of the given Stack data type. * DO NOT access the internal fields of the given stack, such as pList, top and capacity.
\#\#\#\#\#\#\#\#\# TO BE FINISHED BY STUDENT \#\#\#\#\#\#\#\#\#\#\#\#\#\#\# \# simple comment HERE \# * Assume valid input parameters def binaryopn(self, num1, oprSym, num2): \# return result of binary operation pass \# TO BE DONE \# simple comment HERE \# * Assume valid PAE in self. inPAEList def evaluatePAE(self): \# return result of PAE pass \# TO BE DONE, based on the algorithm in lecture note \#\#\#\#\#\#\#\#\#\# TO BE FINISHED BY STUDENT \#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\# \# simple comment HERE \# * Assume valid input parameters def binaryopn(self, num1, oprSym, num2): \# return result of binary operation pass \# TO BE DONE \# simple comment HERE \# * Assume valid PAE in self.inPAEList def evaluatePAE(self): \# return result of PAE pass \# TO BE DONE, based on the algorithm in lecture note File MA2B2 . pY for basic running and testing \# MA2B2.py, for basic running and testing. \# * DO NOT modify this given test file, except the STUDENT INFO part. \# Main Testing Program from A2B2 import PostFixAE def main( ): myPAE = PostFixaE $\left(\left[9,9,7,{ }^{\prime}\right.\right.$ su' $\left.\left.^{\prime},{ }^{\prime} \mathrm{mu}^{\prime}\right]\right)$ print(f" DIRECT TEST 1: myPAE.binaryOpn(9, 'su',7): \{myPAE.binaryOpn $\left(9,{ }^{\prime}{ }^{\prime}\right.$ 'u ' $\left.\left.\left.^{\prime}, 7\right)\right\}^{\prime \prime}\right)$ print(f" DIRECT TEST 2: myPAE.binaryOpn(9, 'ad', 7): $\left.\left\{\operatorname{myPAE.binaryOpn}\left(9,{ }^{\prime}{ }^{\prime}{ }^{\prime}{ }^{\prime}, 7\right)\right\}^{\prime \prime}\right)$ print("\n-1.--") print (f" RESULT of \{myPAE.inPAEList\}: \{myPAE.evaluatePAE()\}") myPAE = PostFixAE([19,7, 'su', 32,3, 'mu' ${ }^{\prime}$ 'ad ' $\left.\left.^{\prime}\right]\right)$ print("\n- 2. - - ")
\# below, avoid execution if import only if __name__ = "_main__: main() \# below, avoid execution if import only if __name__ == "_ main__": main() Sample console display output of executing the main testing program MA2B2 . py $===$ A2B2, PAE using Stack, by 〈Student NAME $\langle$ Student ID $\rangle===$ 9.su. $7=2$ DIRECT TEST 1: myPAE.binaryOpn(9, 'su', 7): 2 9. ad. $7=16$ DIRECT TEST 2: myPAE.binaryOpn(9, 'ad', 7): 16 9. $\mathrm{mu} .7=63$ DIRECT TEST 3: myPAE.binaryopn(9, 'mu ',7): 63 - 1. - - 9.su. $7=2$ 9. mu. $2=18$ RESULT of $[9,9,7$, 'su', 'mu']: 18 - 2. - - 19.su. $7=12$ 32. mu. $3=96$ 12. ad. $96=108$ RESULT of $[19,7$, 'su', 32, 3, 'mu', 'ad']: 108given Python file A2B2.py.

Public Answer

WUQSGQ The First Answerer