Question: test file: 3. Part C, A2C (10 marks) Write a Python program, with the given Python files. O O o O O Program for Code


test file:

3. Part C, A2C (10 marks) Write a Python program, with the given Python files. O O o O O Program for Code Strings with Simple Method for Balancing Symbols, with Stack: Define a Python class in a file A2C.py with the given Stack class (in file Stack.py) for the symbol balancing task, using the algorithm in our lecture notes: "Specified Balancing Symbols": 3 pairs of [ ]. (). Name of the Class: CodeString Operations (methods of the class) to be implemented by Students: At least one line of simple comment for each extra operation required Operation (CodeString) Description _init_(): Create and initiate a new CodeString constructor) setCodeStr(strIn): Set a code string to this CodeString object symRatio(): float Determine and return the ratio of the number of "Specified Balancing Symbols" to that of all characters in the code string (including blank space). Return -1.0 if this cannot be determined. isSymBalanced(): bool Return True if the CodeString is a code string with balanced symbols, False otherwise. An empty or None string is treated as balanced, thus True * Only consider Balancing Symbol-pairs of [ 1. (). Given Stack in the file Stack.py * DO NOT modify this given file) Operation (Stack) Description _init_(): Create and initiate a new Stack (constructor) isEmptys(): bool Check if the Stack is empty. Return True if it is, otherwise False displays(): Display the Stack push(elt): Push/insert elt at the top of stack peek(): Get and return the top clement, without removal pop(): Remove (& return) the top element of stack Sample codes of file A2C.py, for reference only (May contain bugs). # A2C.py, sample code, for reference only (May contain bugs). # Only consider 6 specified balanced symbols: ( 0) # FINISHED by: Student NAME, Student ID, Class from Stack import Stack class CodeString: TO BE FINISHED BY STUDENT def __init__(self): # constructor self.codeStr - None # the code string #simple comment HERE def setCodeStr(self, StrIn): pass # TO BE DONE # MORE TO BE DONE One simplified algorithm, for balancing the symbol-pair '(' ')' only (pseudo-code), return TRUE if balanced, FALSE otherwise, for reference while there are still symbols to be read in the code string: if the symbol is '(': push the symbol elseif the input is ')': if stack is not empty: pop else: Class CodeString: ######## TO BE FINISHEDY STUENT ####### def __init__(self): # constructor self.codeStr None # the code string #simple comment HERE def setCodeStr(self, StrIn): pass # TO BE DONE # MORE TO BE DONE 3/5 One simplified algorithm. for balancing the symbol-pair '(' ')' only (pseudo-code), return TRUE if balanced, FALSE otherwise, for reference while there are still symbols to be read in the code string: if the symbol is 'c': push the symbol elseif the input is ')': if stack is not empty: pop else: return FALSE if the stack is empty, return TRUE; otherwise return FALSE File A2CT.py, to be modified and completed by student # A2CT.py, for basic running and testing. # DO NOT modify this given test file, except the STUDENT INFO part. # Main Testing Program from A2C import CodeString def main(): DO NOT modify this main() function, except
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
