Not working


#1



6 Grand finale


script.py

1
2
3
4
5
6
7
8
9
10
11
from datetime import datetime
now = datetime.now()
print '%s/%s/%s' % (now.hour now.minute now.second now.year, now
.month, now.day)
print '%s:%s:&s'
print now.second
print now.minute
print now.hour
print now.day
print now.month
print day.year
File "python", line 4
print '%s/%s/%s' % (now.hour now.minute now.second now.year, now.month, now.day)
^
SyntaxError: invalid syntax


from datetime import datetime
now = datetime.now()

print '%s/%s/%s' % (now.hour now.minute now.second now.year, now.month, now.day)
print '%s:%s:&s'
print now.second
print now.minute
print now.hour
print now.day
print now.month
print day.year


#2

On the following line, it should be:

print '%s/%s/%s %s:%s:%s' % (now.month, now.day, now.year, now.hour, now.minute, now.second)

#3

@mrpon There are a few areas of mistake:

1.

print '%s/%s/%s' % (now.hour now.minute now.second now.year, now
.month, now.day)
This should be: > print '%s/%s/%s' % (now.hour, now.minute, now.second)
You just forgot to add the commas, and had an extra line of code for the line below, which leads to number two.

2.

print '%s/%s/%s' % (now.hour now.minute now.second now.year, now
.month, now.day)
print '%s:%s:&s'
This line, should look like this from the previous error: > print '%s/%s/%s' % (now.hour, now.minute, now.second)
So then we're left with: > print '%s/%s/%s' % (now.hour, now.minute, now.second)
print '%s:%s:&s'
The line of code italicized above does not have any values to fill with the "%s". You fix this by adding: %(now.year, now.month, now.day) after it. Also, you have an "&" symbol instead of the "%" symbol: print '%s:%s:&s'

So with all these errors fixed, it should now look like:

from datetime import datetime
now = datetime.now()

print '%s/%s/%s' % (now.hour, now.minute, now.second)
print '%s:%s:%s' % (now.year, now.month, now.day)
print now.second
print now.minute
print now.hour
print now.day
print now.month
print day.year

I really hope this helps!


#4

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.