Arithmetic Formatter
Description:
Arithmetic Formatter
Students in primary school often arrange arithmetic problems vertically to make them easier to read and 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 also be able to calculate the result of the problems and the answers should be displayed.
For example
Function Call:
arithmetic_formatter(["32 + 8", "1 - 3801", "9999 + 9999", "523 - 49"])
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:
- 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.
- 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:
- 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.)
The problem description was derived from freeCodeCamp's Arithmetic Formatter (CC BY-SA 4.0
). Everything else is subject to the Codewars' Terms of Service.
Similar Kata:
Stats:
Created | Mar 23, 2021 |
Published | Mar 23, 2021 |
Warriors Trained | 133 |
Total Skips | 13 |
Total Code Submissions | 388 |
Total Times Completed | 51 |
Python Completions | 51 |
Total Stars | 3 |
% of votes with a positive feedback rating | 82% of 28 |
Total "Very Satisfied" Votes | 21 |
Total "Somewhat Satisfied" Votes | 4 |
Total "Not Satisfied" Votes | 3 |
Total Rank Assessments | 29 |
Average Assessed Rank | 6 kyu |
Highest Assessed Rank | 5 kyu |
Lowest Assessed Rank | 7 kyu |