Why can't i get datetime scripts to work on my computer?


after having successfully completed 6/6, i copied and pasted the code to a text file on the computer, and then attempted to run it from terminal.

instead of getting the date and time, i got the error message:

File "test.py", line 4
print '%s/%s/%s %s:%s:%s' % (now.month,now.day,now.year,now.hour, now.minute, now.second)
SyntaxError: invalid syntax

what is the cause of the error?


Are you running it locally on your machine? Probably wrong Python version, use Python2

Or change the print statement to a function call


indeed, the code works with python2 but not python3.

what would i need to do to get the script to work in python3?


@blackbuddha88 In python3 print is changed to print()
Python2: print 'Hello world!'
Python3: print('Hello world!')


ah. thank you for the explanation!