 # Arithmetic arranger

Tell us what’s happening:
Am I the only one who understands that we’re supposed use a list of strings for the initial argument? That said, when I convert the string to int, the operators can’t function. Furthermore, each string in the list is a single index, so when I split the list to print vertically, it stacks the problems rather than arranging them sideways. Any advice on the conversion from a list of str to individual ints with usable operators would most helpful. A better way to split the list would also be great. Thanks.

Here’s some of my code, but understand I’ve been writing and re-writing, so whatever’s there is not necessarily complete:

``````def arithmetic_arranger(problems, calc: bool = True) -> None:
#split list by commas
for item in problems:
return(problmes.replace(",", "\n"))
#create error for input other than str
#for item in problems:
#try:
#[""]
#except:
#print("Error, input list of string type only")

#limit digit input to 4 digits

#create an error if the problems exceed 5
if len(problems) < 6:
return problems
else:
print("Error, too many problems")

#print list vertically
for item in range(len(problems)):
for x in problems:
return(x[item])

#convert and caluclate
"""while calc is True:
conversion = ()
for op in conversion:
if op in conversion == "+"
return num1 + num2
elif op in conversion == "-":
return num1 - num2
else:
print("Error use + or - operators only")"""

print(arithmetic_arranger(["1 + 2"]))
``````

User Agent is: `Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.193 Safari/537.36`.

Challenge: Arithmetic Formatter

I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor (`</>`) to add backticks around text.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (’).

I do not know what you mean by this. How do they not function? Most operators only work on numbers (`int`…).

A major hint for this challenge is:

• Separate each problem horizontally. That is, print the top row of each problem on the same line, then print the next row, and so-forth. This can be accomplished in many ways, but one way is to split the incoming problems based on new lines.

Hope this helps

Just an idea/hint on many ways to solve this.
for each item in problems first check for the operator (+ or -). Throws error if not found.
Once you know the item is ‘good’ (operator wise), check for digits and length. Throws errors if conditions not met.
Break the item in two variables (left in line 1, right in line 2). Add proper spacing in between.
loop through problems and append to line1 or line2 respectively.
Add ‘—’ and sum lines if needed.

Thanks for the reply, but it certainly is NOT that simple.
I can easily create code for all of the errors. Furthermore, there is no need to begin with checking for the correct operators; that comes much later and not until the strings have been removed from the list, indexed to be returned vertically, split to be arranged stacked, and finally converted into ints for which python can calculate all by itself. Don’t forget that the dashes also have to be dynamic; there cannot be more or less dashes than the number of total spaces in each problem. Thanks anyway.

remember that if you want to build something like

``````I          AND
AM         SO
A          AM
VERTICAL   I
TEXT
``````

the string will be something like

``````I          AND\nAM         SO\nA          AM\nVERTICAL   I\nTEXT
``````

In my case, I used 3 lists. First for first argument, one for operator and another for second argument and one more for the solution if required…
Then I looped through each list to print them on line…

First I printed the space separated first argument, using `rjust` function taking into account highest length for argument of each equation
Then I printed the `operator +second_argument` separated by spaces in one line…
Then comes dashes which were simply `'-'*n`
After that, solutions in one line