Questions
Write a program that reads a data form(1/1/2020 to 31/12/2020)and print the day of the date . Jan 1,2020 .is Wednesday. Note that 2020 is a leap year
Last Updated : 12 Mar 2026
Jul 2024
Solution:
from datetime import date
print("Enter date between 01/01/2020 to 31/12/2020")
m=int(input("Enter Month"))
d=int(input("Enter Date"))
weeks={1:'monday',2:'tuesday',3:'Wednesday',4:'thursday',5:'friday',6:'saturday',7:'sunday'}
wd=date.isoweekday(date(2020,m,d))
print("Day of the date",weeks[wd])
OUTPUT:
Enter date between 01/01/2020 to 31/12/2020
Enter Month05
Enter Date24
Day of the date sunday
Code Explanation:
-
Import Statement:
from datetime import dateimports thedateclass from thedatetimemodule. -
User Input:
- Prompts the user to enter a month and a date.
- Converts the input values to integers.
-
Day Mapping:
weeksdictionary maps numbers 1 through 7 to the days of the week.
-
Calculate Weekday:
date(2020, m, d)creates a date object for the year 2020 with the provided month (m) and day (d).date.isoweekday()returns the day of the week as an integer (1 for Monday, 7 for Sunday).
-
Print Result:
- Retrieves and prints the day of the week from the
weeksdictionary based on the calculated integer.
- Retrieves and prints the day of the week from the
Meanwhile you can watch this video
Watch Video