Ask coding questions

← Back to all posts
why says always syntax error
RobertAdam1 (0)

https://repl.it/@RobertAdam1/boilerplate-arithmetic-formatter#arithmetic_arranger.py

why always says syntax error for adding + "\n" + ''join(print_list_4)

Help

Answered by JamesXin (14) [earned 5 cycles]
View Answer
Comments
hotnewtop
JamesXin (14)

For starters, I wouldn't put print in the name of the function, rather I would just name them list_1, list_2, and so on and so forth. And the reason why it's giving you a syntax error is because you probably accidentally hit enter when typing the new line like this

    return_statement = ''.join(print_list) + "\n" + ''.join(print_list_2) + "\n" + ''.join(print_list_3) +
    "\n" + 
   ''.join(print_list_4)

Which is what you currently have. What you want instead is this:

return_statement = ''.join(print_list) + "\n" + ''.join(print_list_2) + "\n" + ''.join(print_list_3) + "\n" + ''.join(print_list_4)
RobertAdam1 (0)

@JamesXin When I do this, then the code says typeerror because of line 19, append() takes a value, none given

JamesXin (14)

@RobertAdam1 Append works like this, say I have a list called people

people = []

If I want to tell python to append something to this list, first I have to tell python what to append to it lol, for example:

people.append('joe')

Here I append a string named joe and when I print people it should give me this:

['joe']

You can append almost anything to a list, even another list!
Hope this helps.

RobertAdam1 (0)

@JamesXin I know about append but here what I should append to my code to work?

JamesXin (14)

@RobertAdam1 I'm gonna assume you wanted to append a '+', so

operator.append('+')
RobertAdam1 (0)

@JamesXin Now did corrections but says if len(problems[problems]) > 4:
TypeError: list indices must be integers or slices, not list

RobertAdam1 (0)

@JamesXin Yes solved that, now i can t figure out error line 33, in arithmetic_ar
 python main.py
Traceback (most recent call last):
File "main.py", line 6, in <module>
print(arithmetic_arranger(["32 + 698", "3801 - 2", "45 + 43", "123 + 49"]))
File "/home/runner/boilerplate-arithmetic-formatter/arithmetic_arranger.py", line 33, in arithmetic_ar
 python main.py
Traceback (most recent call last):
File "main.py", line 6, in <module>
print(arithmetic_arranger(["32 + 698", "3801 - 2", "45 + 43", "123 + 49"]))
File "/home/runner/boilerplate-arithmetic-formatter/arithmetic_arranger.py", line 33, in arithmetic_ar
 python main.py
Traceback (most recent call last):
File "main.py", line 6, in <module>
print(arithmetic_arranger(["32 + 698", "3801 - 2", "45 + 43", "123 + 49"]))
File "/home/runner/boilerplate-arithmetic-formatter/arithmetic_arranger.py", line 33, in arithmetic_ar
 python main.py
Traceback (most recent call last):
File "main.py", line 6, in <module>
print(arithmetic_arranger(["32 + 698", "3801 - 2", "45 + 43", "123 + 49"]))
File "/home/runner/boilerplate-arithmetic-formatter/arithmetic_arranger.py", line 33, in arithmetic_arranger
if len(problems[problems]) > 4:
TypeError: list indices must be integers or slices, not list

JamesXin (14)

@RobertAdam1 my guy is this even your code? you added an s to problem...

19ecal (228)

I think this is because line 130 ought to just be on the end of line 129

128 
129  return_statement = ''.join(print_list) + "\n" + ''.join(print_list_2) + "\n" + ''.join(print_list_3) + "\n" + ''.join(print_list_4)
RobertAdam1 (0)

@19ecal says the same, line 19 append() takes a value, none given