I’ve been working my way through the arithmetic arranger project and I have run up against a problem with formatting my output properly.
The applicable part of my code:
def arithmetic_arranger(strlist, answers=False):
# create vars
sol = None
format = []
output = ''
formlist = []
# In one loop, pull i from list, split it, answer it, format it, store it
while True:
#
for i in strlist :
# get solution
if answers == True :
sol = eval(i)
format = i.split()
a = format[0]
b = format[1]
c = format[2]
d = "-"
# generate the size of the dash line
d = d*(2+len(a)) if len(a)>len(c) else d*(2+len(c))
wid = len(d)
widmid = len(d) - 1
if answers == True :
output = f"\n{a:>{wid}}\n{b:}{c:>{widmid}}\n{d:}\n{sol:>{wid}}\n"
formlist.append(output)
formlist.append(" ")
else:
output = f"\n{a:>{wid}}\n{b:}{c:>{widmid}}\n{d:}\n"
formlist.append(output)
formlist.append(" ")
print(formlist)
return print(" ".join(formlist))
The answers are formatted properly (I think), but they won’t print horizontally. I’ve spent hours trying to figure this out/checking stackflow and this forum, but haven’t found anything that has worked. I have a sneaking suspicion that part of the problem might be the use of \n in my fstring, but without those the formatting gets jumbled.
the tests are not being called, you made it interactive for the user, but the tests are not executing
I mean, they are executing after the interactive part quits, but all fails as the functions called by the tests return None
AssertionError: None != 'Error: Too many problems.' : Expected calling "arithmetic_arranger()" with more than five problems to return "Error: Too many problems."
all the return statements in your function are just return, returning nothing
you are printing each problem separately, you need to have a single string at the end that containts all 4 problems, and return that
and returning a print statement will not return the argument of the print statement, probably just None
EDIT : This is a bit embarrassing but I just figured it out within 5 minutes of posting this. Apologies. I’m new to the forum so feel free to let me know if I should delete this or not…sorry/thanks again!
So, I took another shot at it using the one string approach. While the output works on my own terminal and in repl.it without running the debugger, it keeps getting caught up on the output tests .
It looks like it may have something to do with the number of characters in the string, but I’ve counted the spaces and compared the visual output in the README.md and it looks right…any insight would be greatly appreciated (again).