My code is not working using replit but it is working using Spider

hi
I wrote a code that solves the first “project” for “Python for everybody” course
but my code is not working when I use replit (online) but on my computer it is
(I am using Spider)

Your code so far

def arithmetic_arranger(problems,display=False):
  firstLine="";
  secondLine="";
  thirdLine="";
  resultLine="";
  result=0;
  arranged_problems="";
  if(len(problems)>5):
    print('Error: Too many problems. ');
    return;
  for eq in problems:
    parts=eq.split();
    if(parts[1]!="+" and parts[1]!="-"):
      print("Error: Operator must be '+' or '-'.");
      return;
    elif(parts[0].isdigit()!=True or parts[2].isdigit()!=True):
      print('Error: Numbers must only contain digits.');
      return;
    elif(len(parts[0])>4 or len(parts[2])>4):
      print('Error Numbers cannot be more than 4 digits.');
      return;
    else:
      if(parts[1]=="+"):
        result=int(parts[0])+int(parts[2]);
      else:
        result=int(parts[0])-int(parts[2]);
      if(len(parts[0])>len(parts[2])):
        firstLine=firstLine+(" "*2)+parts[0]+(" "*4);
        secondLine=secondLine+parts[1]+(" "*(len(parts[0])-len(parts[2])+1))+parts[2]+(" "*4);
        thirdLine=thirdLine+("-"*(2+len(parts[0])))+(" "*4);
        resultLine=resultLine+" "+(" "*min(5-len(str(result)),1))+str(result)+(" "*4);
      else:
        firstLine=firstLine+(" "*2)+(" "*(len(parts[2])-len(parts[0])))+parts[0]+(" "*4);
        secondLine=secondLine+parts[1]+" "+parts[2]+(" "*4);
        thirdLine=thirdLine+("-"*(2+len(parts[2])))+(" "*4);
        resultLine=resultLine+" "+(" "*min(abs(5-len(str(result))),1))+str(result)+(" "*4);
    arranged_problems=arranged_problems+firstLine+"\n"+secondLine+"\n"+thirdLine;
    if(display):
      arranged_problems=arranged_problems+"\n"+resultLine;
    return arranged_problems

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:

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 (’).

1 Like

You should not be using print inside of your solution. You need to return the specified strings.

1 Like

thank you ,it is working now

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