Commits

Jay Yu committed cb7d527

cleaned up python script

Comments (0)

Files changed (1)

Calculator/descriptionOfProgram.py

             operandLeft = descriptionOfTopOfStack(stack, depth, operation)
             if operation == "*" and operandLeft == operandRight and " " not in operandLeft:
                 # Icing on the cake: Print x^2 if encountering x * x
-                # only use ^2 if x is not a complex expression (avoid missing
-                # ())
+                # only use ^2 if x is not a complex expression (avoid
+                # missing "()")
                 result = operandLeft + '^2'
             else:
                 template = "({} {} {})" if useBracket(
                 depth, operation, lastOperation) else "{}{}"
             result = template.format(
                 operation, descriptionOfTopOfStack(stack, depth, operation))
-        elif operation in ('pi'):
+        elif operation == 'pi':
             result = 'pi'
         else:
             result = operation
     return True
 
 
-def nextOperation(stack):
-    try:
-        idx = -1
-        while(1):
-            if type(stack[idx]) is str:
-                return stack[idx]
-            idx = idx - 1
-    except IndexError:
-        pass
-    return None
-
-
 def descriptionOfProgram(program):
     output = []
     while (len(program) > 0):
     return ', '.join(output)
 
 
+# Since this Python version does not support variables and floating point
+# numbers, they have been subsitiuted with integers
 tests = [
     [10, 'sqrt'],  # Requirement a
     [3, 5, '+'],  # Requirement b
     # Commas
     [3, 5],  # Expects 5, 3
     [3, 5, '+', 6, 7, '*', 9, 'sqrt'],  # Expects: sqrt(9), 6 * 7, 3 + 5
+    # Sample inputs from screenshots page
+    [3, 3, '*', 4, 4, '*', '+', 'sqrt'],
+    [3, 6, '+', 14, '*', 1, 2, '+'],
 ]
 
 for test in tests: