Next problem with Arithmetic Formatter!

Tell us what’s happening:
Hey!I have been trying to complete arithmetic formatter, but I am kind of stuck at the end. I am having problems correctly printing the “columns” of each operation. I thought to use string formating to do so, but it is only working for a specific number of operataions - in the code I determined it for 4 operations.

Your code so far
Link: https://replit.com/@jazlik/boilerplate-arithmetic-formatter#arithmetic_arranger.py

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/93.0.4577.63 Safari/537.36

Challenge: Arithmetic Formatter

Link to the challenge:

You’re right; your current string formatting only works for 4 problems, but should work for up to 5. You don’t have to create the whole string all at once. You can use string concatenation and some of your current formatting to build up the string using code like

row_1 = row_1 + "   24"

or similar and then join the rows together once they are all built. You have the two operator rows and the lines already; you just need the answer row and the logic to join the items in each array properly. For instance if

first_row = [ 1, 2, 3, 4 ]

you could easily loop over first_row to join its elements to output "1234". Not what you want ultimately, but a lot of the way there regardless (just add formatting!). However, looping works if there is 1 element in first_row or 5 or any number of elements.

Also, you don’t appear to be using your is_displayed parameter yet; at least one of the tests checks for displaying answers. Further, you will need to return the finished string since the tests will fail if you just print it.

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.