An arithmetic arranger for addition and subtraction operations. Includes unit testing. First repository for python.
@BryanW1/arithmetic-formatter?view=1">
Students 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.
Function Call:
arithmetic_arranger(["32 + 698", "3801 - 2", "45 + 43", "123 + 49"])
Output:
32 3801 45 123
+ 698 - 2 + 43 + 49
----- ------ ---- -----
Function Call:
arithmetic_arranger(["32 + 8", "1 - 3801", "9999 + 9999", "523 - 49"], True)
Output:
32 1 9999 523
+ 8 - 3801 + 9999 - 49
---- ------ ------ -----
40 -3800 19998 474
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.
Error: Too many problems.
Error: Operator must be '+' or '-'.
Error: Numbers must only contain digits.
Error: Numbers cannot be more than four digits.
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.
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.