What day is today?
It's lunch time and you are talking with some of your colleagues. They comment that they feel that every morning someone should send them a reminder of what day it is so they can check in the calendar what their assignments are for that day.
You want to help out and decide to write a small script that takes the date and time of the day so that every morning, a message is sent to your colleagues. You can use the module datetime along with named placeholders to achieve your goal.
The date should be expressed as Month day, year, e.g. April 16, 2019 and the time as hh:mm, e.g. 16:30.
You write down some specifiers to help you: %d(day), %B (monthname), %m (monthnumber), %Y(year), %H (hour) and %M(minutes)
You can use the IPython Shell to explore the module datetime.
Diese Übung ist Teil des Kurses
Regular Expressions in Python
Anleitung zur Übung
- Import the function
datetimefrom the moduledatetime. - Obtain the date of today and assign it to the variable
get_date. - Complete the string
messageby adding to the placeholders namedtodayand the format specifiers to format the date asmonth_name day, yearand time ashour:minutes. - Print the message using the
.format()method and the variableget_dateto replace the named placeholder.
Interaktive Übung
Vervollständige den Beispielcode, um diese Übung erfolgreich abzuschließen.
# Import datetime
____
# Assign date to get_date
get_date = ____
# Add named placeholders with format specifiers
message = "Good morning. Today is {____:____ ____, ____}. It's {today:___:____} ... time to work!"
# Use the format method replacing the placeholder with get_date
print(____.____(____))