Click here to Skip to main content
15,392,679 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
This is my basic function I'm trying to develop as a beginner, but it isn't yet complete as I want to try and add some more code where I add the sums of 5 lists of n length on my own, but this part has been bugging me for a while. When I want to run this, all it shows is an error pop-up saying "invalid syntax" and highlighting "name", or rather the 1st letter of it.
int name[n]
for i in range(n):
    added= added + name[i]

What I have tried:

Removing int name[n] and setting it up so that name=[n], but when I removed int name[n], suddenly python thinks that the list doesn't exist.
Updated 12-Dec-21 22:45pm
CPallini 13-Dec-21 2:24am
What are you trying to do?
Messa Tee 13-Dec-21 2:39am
Wanted to have it so that the code prints the sum of the list of n length.
CPallini 13-Dec-21 3:13am
OK, but your code didn't assign any value to the items of the list.
Messa Tee 13-Dec-21 3:29am
So I'm supposed to append?
CPallini 13-Dec-21 4:00am
Well, you are supposed to add some values to the list.

Take out the line:
int name[n]
That is a "C style" declaration, not Python.
The line below it serves to declare the collection.
Your code makes little sense and looks like it was copied from someone who does not know Python. I suggest you go to The Python Tutorial — Python 3.9.9 documentation[^] where you can learn the language in easy steps.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900