-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAssignment9_ CalendarModule.py
More file actions
39 lines (31 loc) · 1.16 KB
/
Assignment9_ CalendarModule.py
File metadata and controls
39 lines (31 loc) · 1.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
"""
Problem Statement : -
Task
You are given a date. Your task is to find what the day is on that date.
Input Format
A single line of input containing the space separated month, day and year, respectively, in format.
Constraints
Output Format
Output the correct day in capital letters.
"""
"""
Sample Output :-
Enter the date in format (month day year): 01 22 2024
Day: MONDAY
"""
import datetime
def find_day(month, day, year):
# Convert input to datetime object
date_obj = datetime.datetime(year, month, day)
# Get the weekday as a number (0 = Monday, 1 = Tuesday, ..., 6 = Sunday)
weekday_num = date_obj.weekday()
# List of weekday names
weekdays = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"]
# Return the corresponding weekday in capital letters
return weekdays[weekday_num].upper()
# Input format: month, day, year separated by spaces
date_input = input("Enter the date in format (month day year): ").split()
month, day, year = map(int, date_input)
# Find the day corresponding to the input date
day_of_week = find_day(month, day, year)
print("Day:", day_of_week)