Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

[Python] Please help me out with this assignment: Here is the assignment content: Here is the template code: Here is the ArrayStack file: Please help

[Python] Please help me out with this assignment:

Here is the assignment content:

image text in transcribed

image text in transcribed

Here is the template code:

image text in transcribed

Here is the ArrayStack file:

image text in transcribed

Please help me this assignment in Python!

Thank You So Much!

In this assignment, we will implement a function to evaluate an arithmetic expression. We will use the algorithm outlined in the PowerPoint slides in Chapter 6. You will use two stacks to keep track things. The function is named 'evaluate', it takes a string as input parameter, and returns an integer. The input string represents an arithmetic expression, with each character in the string being a token, while the returned value should be the value of the expression. Examples evaluate '1+2*3') -> 7 evaluate ('1*2+3 5 Download the four files "csc220a3tester.py", "csc220a3testData.", "Arraystack.py", and "csc220a3.py" from Canvas and save them in the same folder. The first two files are the tester program and the testing data file, respectively. The third file is the ArrayStack class from the textbook. Do not modify these three files. The last file is the file you will work on. Note that you cannot rename this file and you cannot change the name of the function (otherwise the tester will not be able to pick up your implementation). However, you can change the name of the parameter if you like. The file "csc220a3.py" contains a dummy implementation of the function that returns a hard- coded (probably) incorrect value: from ArrayStack import ArrayStack def evaluate (expression): return -1 The tester program will use the testing data to test your implementation. It will run a total of 100 test cases. If you make no change to the function above, it should produce the following output: Passed: [] -total 0 Failed: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100] - total 100. 0 of 100 test cases passed. Score = 0.00 of 15.00 Notes: 1. You can assume the input string is always a valid arithmetic expression, with all numerical values being one-digit integers (1-9). You do not have to check for the correctness of the input expression. The only operators that will appear in the expression are +", "-", and +", each of these operators are having the usual meaning as they are usually used in programming languages. 2. 3. Your program will be tested with similar but different data. The testing results will earn 4. The remaining 5 points will be awarded based on the structure, readability, and 5. You implementation should be compatible to Python 3.x you up to 15 points (out of 20 points total). documentation of your implementation. 6. There can only be one import statement in your program; and that statement must be "from ArrayStack import ArrayStack". (This statement has already been put in the "csc220a3.py" file. 7. The tester contains a function "runTestCase", this function takes a testcase number and run that single testcase. It will produce a more verbose output to help you debug your program >>runTestCase (50) Test 50 failed expecting 65, got -1 instead from ArrayStack import ArrayStack def evaluate (expression): return-1 "Basic example of an adapter class to provide a stack interface to Python's list." " class ArrayStack: "LIFO Stack implementation using a Python list as underlying storage."" def init_(self): "" "Create an empty stack.""" self._data[ # nonpublic list instance def _len (self """Return the number of elements in the stack.""" return len (self._data) def is empty (self): "Return True if the stack is empty." return len (self._data)0 def push (self, e): "Add element e to the top of the stack."" self._data.append (e) # new item stored at end of list def top (self): "Return (but do not remove) the element at the top of the stack. Raise Empty exception if the stack is empty if self.is_empty C): raise Empty 'Stack is empty return self._data C-1] # the last item in the list def pop (self): "Remove and return the element from the top of the stack Ci.e., LIFO) Raise Empty exception if the stack is empty if self.is_empty O: raise Empty 'Stack is empty return self._data.pop # remove last item from list class Empty (Exception): """Error attempting to access an element from an empty container.""n pass if __name-- main': SArrayStack CO S.push (5) push (3) print (len (S)) print (S.pop ) print (S.is empty OX print (S.pop O) print (S.is_empty O) S.push (7) s.push (9) print (S.top O) S.push (4) print (len CS)) print (S.pop O) S.push (6) S.push (8) print (S.pop O) # contents: [ ] # contents: [5] # contents: [5, 3] # contents: [5, 3); outputs 2 # contents: [5]; # contents: [5]; # contents: [ ]; # contents: [ ]; # contents: [7] # contents: [7, 9] # contents: [7,9]; # contents: [7, 9, 4] # contents: [7, 9, 4); outputs 3 # contents: [7, 9); # contents: [7, 9, 6] # contents: [7, 9, 6, 8] # contents: [7, 9, 6); outputs 8 outputs3 outputs False outputs 5 outputs True outputs 9 outputs 4

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Fundamentals Of Database Management Systems

Authors: Mark L. Gillenson

2nd Edition

0470624701, 978-0470624708

More Books

Students also viewed these Databases questions