<jupyter_start><jupyter_text>AssignmentStudents in primary school often arrange arithmetic problems vertically to make them easier to solve. For example, "235 + 52" becomes:```  235+  52-----```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 exampleFunction Call:```pyarithmetic_arranger(["32 + 698", "3801 - 2", "45 + 43", "123 + 49"])```Output:```   32      3801      45      123+ 698    -    2    + 43    +  49-----    ------    ----    -----```Function Call:```pyarithmetic_arranger(["32 + 8", "1 - 3801", "9999 + 9999", "523 - 49"], True)```Output:```  32         1      9999      523+  8    - 3801    + 9999    -  49----    ------    ------    -----  40     -3800     19998      474``` RulesThe 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.)Click this [link](https://www.freecodecamp.org/learn/scientific-computing-with-python/scientific-computing-with-python-projects/arithmetic-formatter) to access this project on freeCodeCamp.org   Solution***<jupyter_code># arithmetic_arranger.ipynb
#  
# <NAME>
# <EMAIL>
#  
# Arithmetic Formatter Project from freeCodeCamp.
#
# 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.

def arithmetic_arranger(problems, bool=False):
    # Checking for the amount of problems given.
    if len(problems) > 5:
        return "Error: Too many problems."

    problems_split = []
    operands_0 = ''
    operands_1 = ''
    dashes = ''
    solutions = ''

    for problem in problems:
        problems_split.append(problem.split())

    for i in problems_split:
        # Checking for the appropriate operators.
        if i[1] == '*' or i[1] == '/':
            return "Error: Operator must be '+' or '-'."
        # Making sure the operands are digits.
        if i[0].isdigit() == False or i[2].isdigit() == False:
            return 'Error: Numbers must only contain digits.' 
        # Checking for the width of each operands.
        if len(i[0]) > 4 or len(i[2]) > 4:
            return 'Error: Numbers cannot be more than four digits.'

        # Calculating the width of each problem.
        if len(i[0]) > len(i[2]):
            operands_0 += ('  ' + i[0] + '    ')
            operands_1 += (i[1] + ' ' +  ' ' * (len(i[0]) - len(i[2])) + i[2] + '    ')
            dashes += '-' * (len(i[0]) + 2) + '    '
            solutions += ((len(i[0]) + 2) 
            - (len(str(int(i[0]) + int(i[1] + i[2]))))) * ' ' + str(int(i[0]) 
            + int(i[1] + i[2])) + '    '

        else:
            operands_0 += ('  ' + ' ' * (len(i[2]) - len(i[0])) + i[0] + '    ')
            operands_1 += (i[1] + ' ' + i[2] + '    ')
            dashes += '-' * (len(i[2]) + 2) + '    '
            solutions += ((len(i[2]) + 2) 
            - (len(str(int(i[0]) + int(i[1] + i[2]))))) * ' ' + str(int(i[0]) 
            + int(i[1] + i[2])) + '    '
    
    # Removing four trailing spaces.
    operands_0 = operands_0[:-4]
    operands_1 = operands_1[:-4]
    dashes = dashes[:-4]
    solutions = solutions[:-4]

    arranged_problems = operands_0 + '\n' + operands_1 + '\n' + dashes
    # Display solutions if bool == True.
    if bool == True:
        arranged_problems = operands_0 + '\n' + operands_1 + '\n' + dashes + '\n' + solutions
    
    return arranged_problems<jupyter_output><empty_output><jupyter_text>List of Tests<jupyter_code>t_0 = ["32 + 698", "3801 - 2", "45 + 43", "123 + 49"]
print(arithmetic_arranger(t_0))
t_1 = ["32 + 8", "1 - 3801", "9999 + 9999", "523 - 49"]
print(arithmetic_arranger(t_1, True))
t_2 = ['3801 - 2', '123 + 49']
print(arithmetic_arranger(t_2))
t_3 = ['1 + 2', '1 - 9380']
print(arithmetic_arranger(t_3))
t_4 = ['3 + 855', '3801 - 2', '45 + 43', '123 + 49']
print(arithmetic_arranger(t_4))
t_5 = ['11 + 4', '3801 - 2999', '1 + 2', '123 + 49', '1 - 9380']
print(arithmetic_arranger(t_5))
t_6 = ['44 + 815', '909 - 2', '45 + 43', '123 + 49', '888 + 40', '653 + 87']
print(arithmetic_arranger(t_6))
t_7 = ['3 / 855', '3801 - 2', '45 + 43', '123 + 49']
print(arithmetic_arranger(t_7))
t_8 = ['24 + 85215', '3801 - 2', '45 + 43', '123 + 49']
print(arithmetic_arranger(t_8))
t_9 = ['98 + 3g5', '3801 - 2', '45 + 43', '123 + 49']
print(arithmetic_arranger(t_9))

t_10 = ['3 + 855', '988 + 40']
print(arithmetic_arranger(t_10, True))
t_11 = ['32 - 698', '1 - 3801', '45 + 43', '123 + 49', '988 + 40']
print(arithmetic_arranger(t_11, True))<jupyter_output>32         1      45      123      988
- 698    - 3801    + 43    +  49    +  40
-----    ------    ----    -----    -----
 -666     -3800      88      172     1028
{'fraction_non_alphanumeric': 0.14964949710454128, 'fraction_numerical': 0.06811947576958244, 'mean_word_length': 2.758877434135166, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 14, 'https://': 1, 'lorem ipsum': 0, 'www.': 1, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '662195', 'license': 'MIT', 'n_tokens_mistral': 2399, 'n_tokens_neox': 2090, 'n_words': 733, 'path': 'arithmetic_arranger.ipynb', 'repo_name': 'Roozeppe/Projects', 'size': '6590'}