Question: IMPORTANT: For this exercise, you will be defining a function which USES the Stack ADT. A stack implementation is provided to you as part of

 IMPORTANT: For this exercise, you will be defining a function which

USES the Stack ADT. A stack implementation is provided to you as

IMPORTANT: For this exercise, you will be defining a function which USES the Stack ADT. A stack implementation is provided to you as part of this exercise - you should not define your own Stack class. Instead, your code can make use of any of the Stack ADT methods: Stack().push(), pop(), peek(), size () and is_empty(). Write a function called get_postfix_expression () which takes a string, infix_expression as a parameter. The parameter string represents a mathematical expression in standard infix notation. For example: 2 * ( 6 + 3). The function should convert this infix expression to postfix. In this example, the result would be: 2 6 3 + * You can assume that the only operators used will be "+", "-", and "/". Note that the input string will have a single space surrounding each number and each bracket (except for the very first and very last elements in the string). Here are a few more examples: II_111111 2 * 3 + 4 2 + 3 * 4 1 * 3 + 2 * 4 ( 1 + 2 ) * ( 3 + 4 ) 2 3 * 4 + 2 3 4 * + 1 3 * 24 * + 1 2 + 3 4 + * For example: Test Result print(get_postfix_expression( '2 * ( 6 + 3)')) 2 6 3 + * print(get_postfix_expression( '3 + 4 * 7')) 3 4 7 * + Answer: (penalty regime: 0, 0, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50 %) Reset answer IMPORTANT: For this exercise, you will be defining a function which USES the Stack ADT. A stack implementation is provided to you as part of this exercise - you should not define your own Stack class. Instead, your code can make use of any the Stack ADT methods: Stack(), push(), pop(), peek(), size() and is_empty(). Write a function called evaluate_postfix (postfix_list) which take a list of strings consisting of operators and operands representing a valid postfix expression, and the function should evaluate it. For example, the postfix expression: 243* - which would be represented by the input list of strings: ["2", "4", "3", "*", "-"] would evaluate to -10. Note: You should convert all operands into integers. When implementing division, you should use integer division (i.e. the // operator) so that any expression will evaluate to an integer value. you can assume that the parameter list represents a valid postfix expression and that the only operators that appear will be "+", "-", "*", ", and "/" 1 Hint: you will probably find it useful to use the compute(number1, number2, operator) function provided in the answer box. The function takes two operands and an operator as parameters and returns the result of applying the operator to the operands. For example: Test Result 12 print(evaluate_postfix(['2', '10', '+'])) print(evaluate_postfix(['2', '4', '3', '*', '-'])) -10 print(evaluate_postfix( ['10', '4', '2', 15', '*', '+', '3', '-'])) 17 Answer: (penalty regime: 0, 0, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50 %) Reset answer 1 def evaluate_postfix(postfix_list)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!