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


#1

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?


#2

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

Or change the print statement to a function call


#3

indeed, the code works with python2 but not python3.

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


#4

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


#5

ah. thank you for the explanation!