freecodeCamp problem 1 python

def arithmetic_arranger(problems, x =False):

    

    arranged_problems = []


    add = []

    sub = []

    dig1 = []

    strdig1 = []

    dig1int = []

    dig2 = []

    strdig2 = []

    dig2int = []

    sig1 = []

    resultint = []

    resultint1 = []

    TSTRL = []

    num_2 = 1

    num_4 = 1

    num_3 = 1

    num_1 = 0


    if len(problems) >= 6:

      print(num_1)

      num_1 = 1

      num_2 = 0

      num_3 = 0

      num_4 = 0


    def LenCompare(x , y):

      if x > y:

        TotalStrLen = x + 2

      else:

        TotalStrLen = y + 2

      

      return TotalStrLen


    ''' sig1 = + 0, - 1, other 2'''


    count = 0

    def SpaceAdd(n):

      if n == 1:

        space = " "

      elif n == 2:

        space = "  "

      elif n == 3 :

        space = "   "

      elif n == 4 :

        space = "    "

      elif n == 5 :

        space = "     "

      elif n == 6:

        space = "      "

      else:

        print("Not Defined")

      return space

    

    def DunderAdd(n):

      if n == 1:

        space = "-"

      elif n == 2:

        space = "--"

      elif n == 3 :

        space = "---"

      elif n == 4 :

        space = "----"

      elif n == 5 :

        space = "-----"

      elif n == 6:

        space = "------"

      else:

        pass

      return space

   

    


    for lst in problems:

      for num in lst:

        if num == '+':

          add = lst.split(' + ')

          # check if integer and string


          try: 

              numcheck1 = int(add[0]) + int(add[1])

          except:

              num_3 = 3

              continue

        

          try: 

            if len(add[0]) > 4:

              num_4 = 4

              continue

            if len(add[1]) > 4:

              num_4 = 4

              continue

          except:

            pass


          result = int(add[0]) + int(add[1])

          resultint.append(result)

          

          # check if digit count greater than 4

          

          

          


          ladd1 = len(add[0])

          ladd2 = len(add[1])


          TotalLvalue = LenCompare(ladd1 , ladd2)

          NewStrValue = TotalLvalue - ladd1

          NewStrValue1 = TotalLvalue - ladd2 -1

          TSTRL.append(DunderAdd(TotalLvalue))


          Svalue1 = SpaceAdd(NewStrValue)

          Svalue2 = SpaceAdd(NewStrValue1)

            


          Strladd1 = Svalue1 + add[0]

          Strladd2 = Svalue2 + add[1]

            

            

          strTOT = str(result)

          strTOT1 = TotalLvalue -len(strTOT)

          Svalue3 = SpaceAdd(strTOT1)

          resultint2 = Svalue3 + strTOT

          resultint1.append(resultint2)

            

          strdig1.append(Strladd1)

          strdig2.append(Strladd2)

          dig1.append(add[0])

          dig2.append(add[1])

          sig1.append(num)

          

          

        if num == '-':

          sub = lst.split(' - ')

          #"Error: Numbers must only contain digits."

          

          try: 

              numcheck1 = int(sub[0])

              numcheck2 = int(sub[1])

          except:

              num_3 = 3

              continue

          

          try: 

            if len(sub[0]) > 4:

              num_4 = 4

              continue

            if len(sub[1]) > 4:

              num_4 = 4

              continue

          except:

            pass

            

          result = int(sub[0]) - int(sub[1])

          resultint.append(result)


          #"Error: Numbers cannot be more than four digits."

  

            

            #compare function

          lsub1 = len(sub[0])

          lsub2 = len(sub[1])


          TotalLvalue = LenCompare(lsub1 , lsub2)

          NewStrValue = TotalLvalue - lsub1

          NewStrValue1 = TotalLvalue - lsub2 - 1

          TSTRL.append(DunderAdd(TotalLvalue))


          Svalue1 = SpaceAdd(NewStrValue)

          Svalue2 = SpaceAdd(NewStrValue1)


          Strladd1 = Svalue1 + sub[0]

          Strladd2 = Svalue2 + sub[1]

            

          strTOT = str(result)

          strTOT1 = TotalLvalue -len(strTOT)

          Svalue3 = SpaceAdd(strTOT1)

          resultint2 = Svalue3 + strTOT

          resultint1.append(resultint2)


          strdig1.append(Strladd1)

          strdig2.append(Strladd2)

          dig1.append(sub[0])

          dig2.append(sub[1])

          sig1.append(num)


            

          

        if num == "/":

          num_2 = 2

        if num == "*":

          num_2 = 2

    


    if num_4 == 4:

      arranged_problems = "Error: Numbers cannot be more than four digits."

    elif num_3 == 3:

      arranged_problems = "Error: Numbers must only contain digits."

    elif num_2 == 2:

      arranged_problems = "Error: Operator must be '+' or '-'."

    elif num_1 == 1 :

      arranged_problems = "Error: Too many problems."

    elif x == True and len(problems) == 4:

      arranged_problems = "{}    {}    {}    {}\n{}{}    {}{}    {}{}    {}{}\n{}    {}    {}    {}\n{}    {}    {}    {}".format(strdig1[0],strdig1[1],strdig1[2],strdig1[3],sig1[0],strdig2[0],sig1[1],strdig2[1],sig1[2],strdig2[2],sig1[3],strdig2[3],TSTRL[0],TSTRL[1],TSTRL[2],TSTRL[3],resultint1[0],resultint1[1],resultint1[2],resultint1[3])

    elif x == False and len(problems) == 4 :

      arranged_problems = "{}    {}    {}    {}\n{}{}    {}{}    {}{}    {}{}\n{}    {}    {}    {}".format(strdig1[0],strdig1[1],strdig1[2],strdig1[3],sig1[0],strdig2[0],sig1[1],strdig2[1],sig1[2],strdig2[2],sig1[3],strdig2[3],TSTRL[0],TSTRL[1],TSTRL[2],TSTRL[3])

    elif x == True and len(problems) == 5:

      arranged_problems = "{}    {}    {}    {}    {}\n{}{}    {}{}    {}{}    {}{}    {}{}\n{}    {}    {}    {}    {}\n{}    {}    {}    {}    {}".format(strdig1[0],strdig1[1],strdig1[2],strdig1[3],strdig1[4],sig1[0],strdig2[0],sig1[1],strdig2[1],sig1[2],strdig2[2],sig1[3],strdig2[3],sig1[4],strdig2[4],TSTRL[0],TSTRL[1],TSTRL[2],TSTRL[3],TSTRL[4],resultint1[0],resultint1[1],resultint1[2],resultint1[3],resultint1[4])

    elif x == False and len(problems) == 5 :

      arranged_problems = "{}    {}    {}    {}    {}\n{}{}    {}{}    {}{}    {}{}    {}{}\n{}    {}    {}    {}    {}".format(strdig1[0],strdig1[1],strdig1[2],strdig1[3],strdig1[4],sig1[0],strdig2[0],sig1[1],strdig2[1],sig1[2],strdig2[2],sig1[3],strdig2[3],sig1[4],strdig2[4],TSTRL[0],TSTRL[1],TSTRL[2],TSTRL[3],TSTRL[4],)

    else:

      print("enter valid X argument")

    


    print(problems,"1")


    print(arranged_problems ,"2")

    

    



    return arranged_problems



'''

Create a function that receives a list of strings that are arithmetic problems and returns the problems arranged vertically and side-by-side. The function should optionally take a second argument. When the second argument is set to `True`, the answers should be displayed.


### For example


Function Call:

```py

arithmetic_arranger(["32 + 698", "3801 - 2", "45 + 43", "123 + 49"])

```


Output:

```

   32      3801      45      123

+ 698    -    2    + 43    +  49

-----    ------    ----    -----

```


Function Call:

```py

arithmetic_arranger(["32 + 8", "1 - 3801", "9999 + 9999", "523 - 49"], True)

```


Output:

```

  32         1      9999      523

+  8    - 3801    + 9999    -  49

----    ------    ------    -----

  40     -3800     19998      474

```


### Rules


The function will return the correct conversion if the supplied problems are properly formatted, otherwise, it will **return** a **string** that describes an error that is meaningful to the user.  



* Situations that will return an error:

  * If there are **too many problems** supplied to the function. The limit is **five**, anything more will return:

    `Error: Too many problems.`

  * The appropriate operators the function will accept are **addition** and **subtraction**. Multiplication and division will return an error. Other operators not mentioned in this bullet point will not need to be tested. The error returned will be:

    `Error: Operator must be '+' or '-'.`

  * Each number (operand) should only contain digits. Otherwise, the function will return:

    `Error: Numbers must only contain digits.`

  * Each operand (aka number on each side of the operator) has a max of four digits in width. Otherwise, the error string returned will be:

    `Error: Numbers cannot be more than four digits.`

*  If the user supplied the correct format of problems, the conversion you return will follow these rules:

    * There should be a single space between the operator and the longest of the two operands, the operator will be on the same line as the second operand, both operands will be in the same order as provided (the first will be the top one and the second will be the bottom.

    * Numbers should be right-aligned.

    * There should be four spaces between each problem.

    * There should be dashes at the bottom of each problem. The dashes should run along the entire length of each problem individually. (The example above shows what this should look like.)


### Development


Write your code in `arithmetic_arranger.py`. For development, you can use `main.py` to test your `arithmetic_arranger()` function. Click the "run" button and `main.py` will run.


### Testing 


The unit tests for this project are in `test_module.py`. We imported the tests from `test_module.py` to `main.py` for your convenience. The tests will run automatically whenever you hit the "run" button.


### Submitting


Copy your project's URL and submit it to freeCodeCamp.

'''

Comments