1

I just finished learning the Python syntax at Codeacademy and decided to try and do some bits in Python proper. So I download the latest version and although my code works on Codeacademy it doesn't work in this (I assume they are different). What I'm trying to do is get the numbers appended to the list, sum them and the print the result. Here's what I wrote:

num = []
for x in range(1,11):
    if x%3==0 or x%5==0:
        num.append(x)
print num
print sum(num)

What's wrong? I get a syntax error with an arrow under the 't' in 'print'.

This still doesn't work when I change the print part...so something else in the code must be wrong but it still tells me it's a print error.

StMatthias
  • 19
  • 5
  • Not a duplicate in a useful sense. The root cause of the asker's problem is the same as in the linked question, but there is no reasonable way a person motivated to ask this question would have realized the connection. – hemflit Aug 02 '15 at 12:41

1 Answers1

2

Your code is valid in Python 2.x, however invalid in Python 3.x

In 3.x, print is a function now. Change

print num
print sum(num)

to

print(num)
print(sum(num))
Yu Hao
  • 119,891
  • 44
  • 235
  • 294