Click here to Skip to main content
15,879,239 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.
Python
int name[n]
name=[]
n=int(input())
added=0
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.
Posted
Updated 12-Dec-21 22:45pm
v3
Comments
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.

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.
 
Share this answer
 
Take out the line:
Python
int name[n]
That is a "C style" declaration, not Python.
The line below it serves to declare the collection.
 
Share this answer
 

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