Arithmetic Formatter code issue with test module

Tell us what’s happening:
The first thing i did is made the definition in pycharm. After i thought i was done i pasted it to the replit site to try. The definition worked but i cant seem to get the test mod working. How to show the code i writen? Do i need to publish first in Replit?

Your code so far

Your browser information:

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

Challenge: Arithmetic Formatter

Link to the challenge:

my code:

def arithmetic_arranger(problems, answer=False):
# Quits program when there are more then 4 lists in problems
if len(problems) > 4:
print(“Error: Too many problems.”)
quit()
# Makes a few lists with every items from the lists in problems
# This to do the necessary checking
listing =
divisions =
list_a =
list_b =
for item in problems:
item.strip()
item2 = item.split()
listing.append(item2[0])
listing.append(item2[2])
divisions.append(item2[1])
list_a.append(item2[0])
list_b.append(item2[2])

# checks for appropriate operaters + or -
for div in divisions:
    if div == "+" or div == '-':
        continue
    elif div == '*' or div == '/':
        print("Error: Operator must be '+' or '-'.")
        quit()
    else:  # didn't need testing but added it
        print("Error: Operator must be '+' or '-'.")
        quit()

# Each number (operand) should only contain digits.
# Adding numbers to list again for calculations
sec_list_numb = []
for ac in listing:
    try:
        test_a = int(ac)
        sec_list_numb.append(test_a)
    except:
        print("Error: Numbers must only contain digits")
        quit()

# Checks if the items in listing are max 4 in length
for ab in sec_list_numb:
    if ab > 9999:
        print("Error: Numbers cannot be more than four digits")
        quit()

# making strings then loop through list_a
answer_line1 = ""
answer_line2 = ""
answer_line3 = ""
answer_line4 = ""
count = 0
for x in list_a:
    answer_line1 = answer_line1 + "  " + " " * (len(list_b[count]) - len(list_a[count])) + str(x)
    # 3 options
    if len(list_a[count]) > len(list_b[count]):
        answer_line2 = answer_line2 + divisions[count] + " " + " " * (len(list_a[count]) - len(list_b[count])) \
                       + list_b[count]
        answer_line3 = answer_line3 + "-" * (len(list_a[count]) + 2)
        if divisions[count] == "+":
            tt = int(list_a[count]) + int(list_b[count])
        elif divisions[count] == "-":
            tt = int(list_a[count]) - int(list_b[count])
        ttt = str(tt)
        if len(ttt) > len(list_a[count]):
            answer_line4 = answer_line4 + " " + ttt
        else:
            answer_line4 = answer_line4 + " " * 2 + ttt

    elif len(list_a[count]) == len(list_b[count]):
        answer_line2 = answer_line2 + divisions[count] + " " + list_b[count]
        answer_line3 = answer_line3 + "-" * (len(list_a[count]) + 2)
        if divisions[count] == "+":
            tt = int(list_a[count]) + int(list_b[count])
        elif divisions[count] == "-":
            tt = int(list_a[count]) - int(list_b[count])
        ttt = str(tt)
        if tt < 0:
            if len(ttt) == len(list_a[count]):
                answer_line4 = answer_line4 + " " + ttt
            elif len(ttt) > len(list_a[count]):
                answer_line4 = answer_line4 + ttt
            elif len(ttt) < len(list_a[count]):
                if len(ttt) == 1:
                    answer_line4 = answer_line4 + "    " + ttt
                elif len(ttt) == 2:
                    answer_line4 = answer_line4 + "   " + ttt
                elif len(ttt) == 3:
                    answer_line4 = answer_line4 + "  " + ttt
                elif len(ttt) == 4:
                    answer_line4 = answer_line4 + " " + ttt
        else:
            if len(ttt) == len(list_a[count]):
                answer_line4 = answer_line4 + "  " + ttt
            elif len(ttt) > len(list_a[count]):
                answer_line4 = answer_line4 + " " + ttt
            elif len(ttt) < len(list_a[count]):
                if len(ttt) == 1:
                    answer_line4 = answer_line4 + "     " + ttt
                elif len(ttt) == 2:
                    answer_line4 = answer_line4 + "    " + ttt
                elif len(ttt) == 3:
                    answer_line4 = answer_line4 + "   " + ttt
                elif len(ttt) == 4:
                    answer_line4 = answer_line4 + "  " + ttt
        # print("2")
    elif len(list_a[count]) < len(list_b[count]):
        answer_line2 = answer_line2 + divisions[count] + " " + " " * (2 - len(list_b[count])) + list_b[count]
        answer_line3 = answer_line3 + "-" * (len(list_b[count]) + 2)
        if divisions[count] == "+":
            tt = int(list_a[count]) + int(list_b[count])
        elif divisions[count] == "-":
            tt = int(list_a[count]) - int(list_b[count])
        ttt = str(tt)
        if tt < 0:
            if len(ttt) == len(list_b[count]):
                answer_line4 = answer_line4 + " " + ttt
            elif len(ttt) > len(list_b[count]):
                answer_line4 = answer_line4 + ttt
            elif len(ttt) < len(list_b[count]):
                if len(ttt) == 1:
                    answer_line4 = answer_line4 + "    " + ttt
                elif len(ttt) == 2:
                    answer_line4 = answer_line4 + "   " + ttt
                elif len(ttt) == 3:
                    answer_line4 = answer_line4 + "  " + ttt
                elif len(ttt) == 4:
                    answer_line4 = answer_line4 + " " + ttt
        else:
            if len(ttt) == len(list_b[count]):
                answer_line4 = answer_line4 + "  " + ttt
            elif len(ttt) > len(list_b[count]):
                answer_line4 = answer_line4 + " " + ttt
            elif len(ttt) < len(list_b[count]):
                if len(ttt) == 1:
                    answer_line4 = answer_line4 + "     " + ttt
                elif len(ttt) == 2:
                    answer_line4 = answer_line4 + "    " + ttt
                elif len(ttt) == 3:
                    answer_line4 = answer_line4 + "   " + ttt
                elif len(ttt) == 4:
                    answer_line4 = answer_line4 + "  " + ttt
    count = count + 1
    answer_line1 = answer_line1 + "    "
    answer_line2 = answer_line2 + "    "
    answer_line3 = answer_line3 + "    "
    answer_line4 = answer_line4 + "    "

print(answer_line1)
print(answer_line2)
print(answer_line3)
if answer is True:
    print(answer_line4)
else:
    quit()

You are supposed to return the result and error messages - not print()

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