시작하기무료로 시작하기

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.

이 연습은 강의의 일부입니다

Regular Expressions in Python

강의 보기

연습 안내

  • Import the function datetime from the module datetime .
  • Obtain the date of today and assign it to the variable get_date.
  • Complete the string message by adding to the placeholders named today and the format specifiers to format the date as month_name day, year and time as hour:minutes.
  • Print the message using the .format() method and the variable get_date to replace the named placeholder.

실습형 인터랙티브 연습

이 예제를 이 샘플 코드를 완성하여 풀어보세요.

# 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(____.____(____))
코드 편집 및 실행