Question: Python code Step 1 Read the Input Expression Tuple, Convert Each into a List of Strings The expressions must be read, split into individual tokens
Python code
Step 1 Read the Input Expression Tuple, Convert Each into a List of Strings The expressions must be read, split into individual tokens (an operator, parenthesis, or number), converted into an integer if the token is a digit, and stored in a list in the same order as it appeared in the input. expressions = (3 4 +, 7 6 * 15 +, 24 4 / 6 2 * +). The above must be read and converted into individual lists for processing, one list per expression. Iterate through expressions and process each character string: 3 4 +, then 7 6 * 15 +, etc. For each string, use the string split method to separate each individual character or token into its own character string and stored in a list. Note that multi-digit characters will be stored as one character string, or token. For example, the string 24 4 / 6 2 * + will be split and stored as the list [24, 4, /, 6, 2, *, +]. 2.
Step 2 Read Each String in the List, Convert Numbers to Integers Each element of the list must be converted to an integer if its a number. Use the string method isdigit to detect that. After doing that the above list will be: [24, 4, /, 6, 2, *, +] and is ready for processing by your algorithm. You may either process each expression (Step 3 below) immediately one at a time or store each expression list in a list, making it a two dimensional list, or list of lists, and then processing the individual expression lists from that. 3.
Step 3 Copy/Paste Stack Code, Create Stack Object, Process Expression Chars using Stack To start processing the expressions, copy in one of the stack class implementations and create a stack object and assign a variable name to it such as S. After doing that, read one of your expressions, one token at a time, and push each of the tokens onto the stack: S.push(). Then run S.showStack() to display the stacks contents. Finally, create a for-loop to pop and print each element of the stack object using print(S.pop() ) until the stack is empty. You should see the contents of the stack displayed from top to bottom.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
