Kevin Tiller

Generation

fix invalid codeThu, 11 May 2023

def arithmetic_arranger(problem, *args): if len(problems) > 5: return("Error: Too Many Problems") arranged_problems:"" for index, value in emumerate(problem): operation = vaule.splt(" ") if operation[1] not in "-+": return"Error: operator must be '+' or '-'." if len(operation[0]) >4 or len(operation[2]) > 4: return "len(operation[0]) > 4" try: value_1 = int(operation[0]) value_2 = int(operation[2]) except ValueError: return"Error values must only contain digits" longest_val = max(len(operation[0]), len(operation[2])) width = longest_val + 2 L1 = f"{operation[0] :>{width}}" L2 = operation[1] + f"{operation[0] :>{width}}" d = "-" * width try: arranged_problems[0] += (" " * 4) + L1 except IndexError: arranged_problems.append(L1) try: arranged_problems[1] += (" " * 4) + L2 except IndexError: arranged_problems.append(L2) try: arranged_problems[0] += (" " * 4) + d except IndexError: arranged_problems.append(d) if args: ans = int(operation[0]) + int(operation[2]) if operation[1] == '+' else int(operation[0]) - int(operation[2]) a = f"{ans :> {width}}" try: arranged_problems[3] += (" " * 4) + a except IndexError: arranged_problems.append(d) output = f"{arranged_problems[0]} \n {arranged_problems[1]} \n {arranged_problems[2]}" output = output + f"\n{arranged_problems[3]}" if args else output return output

## Running the tests To run the tests, run the appropriate command below ([why they are different](https://github.com/pytest-dev/pytest/issues/1629#issue-161422224)): - Python 2.7: `py.test arithmetic_arranger_test.py` - Python 3.4+: `pytest arithmetic_arranger_test.py` Alternatively, you can tell Python to run the pytest module (allowing the same command to be used regardless of Python version): `python -m pytest arithmetic_arranger_test.py` ### Common `pytest` options - `-v` : enable verbose output - `-x` : stop running tests on first failure - `--ff` : run failures from previous test before running other test cases For other options, see `python -m pytest -h` ## Submitting Exercises Note that, when trying to submit an exercise, make sure the solution is in the `$EXERCISM_WORKSPACE/python/arithmetic-arranger`

Want to kickstart your project?Use the new AI Studio to create your code