Reputation: 986
I'm embarking on my Project Euler adventure and the first line of my Python code is tripping me up. The error I get for the code below is: Traceback (most recent call last): File "python", line 3 3multlist = [] ^ SyntaxError: invalid syntax
Which makes NO sense because I've verified up and down that the line in question does have proper syntax!
Code below:
3multlist = []
5multlist = []
3starter = 0
5starter = 0
While (3starter < 1000):
3starter = 3starter + 3
3multlist.append(3starter)
While (5starter < 1000):
5starter = 5starter + 3
5multlist.append(5starter)
b = sum(3multlist)
c = sum(5multlist)
d = b + c
print d
Upvotes: 0
Views: 2780
Reputation: 5413
This is because variable name can not start with a numeral.Below are the variable naming convention rules Variables names must start with a letter or an underscore, such as: _
The remainder of your variable name may consist of letters, numbers and underscores.
Names are case sensitive. case_sensitive, CASE_SENSITIVE, and Case_Sensitive are each a different variable
Correct version of your program would be
multlist = []
multlist = []
starter = 0
starter = 0
while (starter < 1000):
starter = starter + 3
multlist.append(starter)
while (starter < 1000):
starter = starter + 3
multlist.append(starter)
b = sum(multlist)
c = sum(multlist)
d = b + c
print(d)
If you are using python 3 you need to use brackets with print statement else you can drop them.
Upvotes: 2
Reputation: 1
It looks like python does not like the number in front of the list declaration
try multlist3 rather than 3multlist
Upvotes: 0