In: Computer Science
" line 48"
return delta.days
^
SyntaxError: 'return' outside function
import datetime
def nowDate():
current_time = datetime.datetime.now()
new_time = datetime.datetime(
current_time.year,
current_time.month,
current_time.day,
0,
0,
0,
)
return new_time
def plusOneDay(daytime):
tomorrow = daytime +
datetime.timedelta(days=1)
return tomorrow
def nDaystoHoliday():
NJCU_holidays = [
(datetime.date(2019, 1,
1), "New Year's Day"),
(datetime.date(2019, 1,
21), 'Martin Luther King, Jr. Day'),
(datetime.date(2019, 2,
19), "President's Day"),
(datetime.date(2019, 4,
19), 'Good Friday'),
(datetime.date(2019, 5,
27), 'Memorial Day'),
(datetime.date(2019, 7,
4), 'Independence Day'),
(datetime.date(2019, 9,
2), 'Labor Day'),
(datetime.date(2019, 10,
14), 'Columbus Day'),
(datetime.date(2019, 11,
11), "Veteran's Day"),
(datetime.date(2019, 11,
28), 'Thanksgiving'),
(datetime.date(2019, 12,
25), 'Christmas Day'),
]
now = datetime.datetime.now().date()
print (now)
date = NJCU_holidays[0][0]
print (date)
for i in range(1, len(NJCU_holidays)):
holiday = NJCU_holidays[i][0]
delta = holiday - now
if(delta.days > 0):
return delta.days
time = nowDate()
plusOneDay(time)
nDaystoHoliday()
import datetime
def nowDate():
current_time = datetime.datetime.now()
new_time = datetime.datetime(
current_time.year,
current_time.month,
current_time.day,
0,
0,
0,
)
return new_time
def plusOneDay(daytime):
tomorrow = daytime + datetime.timedelta(days=1)
return tomorrow
def nDaystoHoliday():
NJCU_holidays = [
(datetime.date(2019, 1, 1), "New
Year's Day"),
(datetime.date(2019, 1, 21),
'Martin Luther King, Jr. Day'),
(datetime.date(2019, 2, 19),
"President's Day"),
(datetime.date(2019, 4, 19), 'Good
Friday'),
(datetime.date(2019, 5, 27),
'Memorial Day'),
(datetime.date(2019, 7, 4),
'Independence Day'),
(datetime.date(2019, 9, 2), 'Labor
Day'),
(datetime.date(2019, 10, 14),
'Columbus Day'),
(datetime.date(2019, 11, 11),
"Veteran's Day"),
(datetime.date(2019, 11, 28),
'Thanksgiving'),
(datetime.date(2019, 12, 25),
'Christmas Day'),
]
now = datetime.datetime.now().date() #we have to give
tab space to each line and arrange them inside the function.
print (now)
date = NJCU_holidays[0][0]
print (date)
for i in range(1, len(NJCU_holidays)):
holiday = NJCU_holidays[i][0]
delta = holiday - now
if(delta.days > 0):
return delta.days #return statement
works only in a function.
time = nowDate()
plusOneDay(time)
nDaystoHoliday()
There is no error in the code except that you have to give indentation (tab space) from the now = datetime.datetime.now().date() to the return statement. So that it will be inside the function.
If you have any doubt comment me.