Scientific Computing with Python Projects - Arithmetic Formatter

Can’t see elif len(problems)==5 nor the syntax error in this screenshot.

You can use the backticks, it’s the key to the left of 1, it looks like ~ (this is a tilde but the backtick is below it). Just paste your code nested in triple backticks.

It will look like this

Screenshot 2023-11-11 152651

This will help you to use the forum. I’ve edited your post here using backticks. You can edit it and see what it looks like: https://forum.freecodecamp.org/t/scientific-computing-with-python-projects-arithmetic-formatter/625707/19?u=pkdvalis

For now, you could just post another link to your replit. I see you have two, but which one are you currently working on?

elif len(problems) == 3:
    line1 = arranged_problems.append(f"  {first_numbers[0]:>{max_width}}"
   f"{first_numbers[1]:>{max_width}}"
   f"{first_numbers[2]:>{max_width}}\n")
      
    line2 = arranged_problems.append(f"     {operators[0]}"
   f"{second_numbers[0]:>{max_width}}"
   f"{operators[1]}"
   f"{second_numbers[1]:>{max_width}}"
   f"{operators[2]}"
   f"{second_numbers[2]:>{max_width}}\n")
    line3 = '-' * (max_width + 2)
                        
  elif len(problems) == 4:                       line1 = arranged_problems.append(f"  {first_numbers[0]:>{max_width}}"   
    f"{first_numbers[1]:>{max_width}}"
    f"{first_numbers[2]:>{max_width}}"
    f"{first_numbers[3]:>{max_width}}\n")
  line2 = arranged_problems.append(f"  {operators[0]}"
    f"{second_numbers[0]:>{max_width}}"        f"{operators[2]}"
    f"{second_numbers[2]:>{max_width}}"
    f"{operators[3]}"
    f"{second_numbers[3]:>{max_width}}\n")
  line3 = arranged_problems.append('-' * (max_width + 2))
                          

There are some indentation errors here. I would go and fix all of those, make the indentation perfect. Indentation is syntax in Python.

 elif len(problems) == 4:                       line1 = arranged_problems.append(f"  {first_numbers[0]:>{max_width}}"   
    f"{first_numbers[1]:>{max_width}}"
    f"{first_numbers[2]:>{max_width}}"

Here is your error, for reference:

Traceback (most recent call last):
  File "main.py", line 4, in <module>
    from arithmetic_arranger import arithmetic_arranger
  File "/home/runner/2363024149/arithmetic_arranger.py", line 74
    elif len(problems) == 5:              
    ^^^^
SyntaxError: invalid syntax

I suspect that because of the indentation errors, Python thinks your If statement is finished and doesn’t consider this elif to be part of the previous if

Here is a reference example:

a = 33
b = 33
if b > a:
  print("b is greater than a")
elif a == b:
  print("a and b are equal")

https://www.w3schools.com/python/gloss_python_elif.asp

Make your indentation perfect

Where in other programming languages the indentation in code is for readability only, the indentation in Python is very important. Python uses indentation to indicate a block of code.

https://www.w3schools.com/python/gloss_python_indentation.asp

This is the one I’m working on; boilerplate-arithmetic-formatter (1) - Replit

I don’t see any indentation errors though, especially on the line which gives me the error.

Hi, I dont know who are you but your first code was right; you have some issue with iddentation; it worked for me, here aresome fixes i did:

  1. in order for the “for cycle of the result line” to run you need to str(x+y) and str(x-y)
  2. cond=None (so your second parameter becomes optional)
  3. Iddentation, you have to get everything that is below while INSIDE while(until ‘counter=counter+1’)
  4. This is how you must arrange the arranged_problems result (f"{fline}\n{sline}\n{uline}\n{rline}")

I hope you can understand me and if not, you can email me

I think I have all the other fixes in but I don’t understand the 1 fix you suggested.

Where can I reach you?

It’s great that you’re willing to give your time to help but I have to caution you about giving solutions like this:

This is how you must arrange the arranged_problems result (f"{fline}\n{sline}\n{uline}\n{rline}")

You want to give advice that will highlight the problem and suggest and approach to fix it. It will not help someone learn if you just write the code for them. Especially for these final projects.

1 Like

hi, you can tell me here…

thanks for the observation

1 Like

Im not sure I understand the first fix; “in order for the “for cycle of the result line” to you need to str(x+y) and str(x-y)”

I don’t understand the parameters x+y and x-y. Care to explain a bit further?