Write a function named last_day_of_month(user_datetime). For anygiven user_datetime, the function should return a string with thelast day of the month formatted as day.month.year (weekday). Forinstance, for input of July 18th, 2018, the function should return31.07.2018 (Tuesday).
def last_day_of_month(user_datetime):
if user_datetime.month == 12:
# this is the case for December which is the last month and wecannot simply add one month to it and extract one day from thefirst day
# replace the user_datetime’s day with 31
last_day = …
else:
# this case is for all other months
# simply replace month with the next month (user_datetime.month +1)
# and day with 1
# then using timedelta subtract one day
last_day = …
return last_day.strftime(…)
# you should call the function like that:
last_day_of_month(datetime.datetime(2018, 8, 21))
Expert Answer
Answer to Write a function named last_day_of_month(user_datetime). For any given user_datetime, the function should return a strin…