Tell us what’s happening:
Hello fellow campers, I’m trying to complete the arithmetic formatter and what I’ve done so far is create a list of lists called “data” , where each list the information i want to display vertically side by side, I wanted to make a string I could return and print.
However I am not able to figure out how to make a loop to print out the lists or arrange them in a single string to be able to print the expected result, I would appreciate it your inputs.
Your code so far
def arithmetic_arranger(a,b):
count=0
count_x=0
l=len(a)
table_data=list()
output=list()
data=list()
#print(l)
#print(a)
if l>5:
print("Error: Too many problems.")
quit()
while count<l:
#print(count)
#print(a[count])
pro=a[count]
y=pro.split()
count=count+1
for words in y:
check_num_len=len(words)
#print(words)
if check_num_len>4:
print("Error: Numbers cannot be more than four digits.")
quit()
if words.isnumeric()==False:
if words=="+" or words=="-":
pass
elif words=="*" or words=="/":
print("Error: Operator must be '+' or '-'.")
quit()
else:
print("Error: Numbers must only contain digits.")
quit()
for item in a:
table_data.append(item.split())
#print(table_data)
col_width = max(len(num) for item in table_data for num in item) + 1
for item in table_data:
output.append(item[0].rjust(col_width+1))
output.append(item[1] + item[2].rjust(col_width))
output.append('-' * col_width)
if b==True:
if item[1]=="+":
addition_op=str(int(item[0])+int(item[2]))
output.append(addition_op.rjust(col_width+1))
if item[1]=="-":
addition_op=str(int(item[0])-int(item[2]))
output.append(addition_op.rjust(col_width+1))
#print(output)
data.append(output)
output=list()
res = "\n".join("{} {}".format(x, y) for x, y in zip(data[0], data[1],data[2],data[3],data[4]))
probs=list()
while True:
x=input("Insert 5 addition or subtraction problems ")
if x==“done” or x==“Done”:
break
else:
probs.append(x)
continue
cond=input("Do you want the problem to be solved? True or False ")
if cond==“True” or cond==“true”:
cond=True
elif cond==“False” or cond==“false”:
cond=False
else:
cond=False
arithmetic_arranger(probs,cond)
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.4638.69 Safari/537.36
Challenge: Arithmetic Formatter
Link to the challenge: