File tree Expand file tree Collapse file tree 1 file changed +13
-4
lines changed
Expand file tree Collapse file tree 1 file changed +13
-4
lines changed Original file line number Diff line number Diff line change 11# Python program to Find day of
22# the week for a given date
3+ import re #regular expressions
34import calendar #module of python to provide useful fucntions related to calendar
45import datetime # module of python to get the date and time
56
7+ def process_date (user_input ):
8+ user_input = re .sub (r"/" , " " , user_input ) #substitute / with space
9+ user_input = re .sub (r"-" , " " , user_input ) #substitute - with space
10+ return user_input
611
7- def findDay (date ):
12+ def find_day (date ):
813 born = datetime .datetime .strptime (date , '%d %m %Y' ).weekday () #this statement returns an integer corresponding to the day of the week
914 return (calendar .day_name [born ]) #this statement returns the corresponding day name to the integer generated in the previous statement
1015
16+ #To get the input from the user
17+ #User may type 1/2/1999 or 1-2-1999
18+ #To overcome those we have to process user input and make it standard to accept as defined by calender and time module
19+ user_input = str (input ("Enter date " ))
20+ date = process_date (user_input )
21+ print ("Day on " + user_input + " is " + find_day (date ) )
22+
1123
12- # Driver program
13- date = '03 02 2019' #this is the input date
14- print (findDay (date )) # here we print the final output after calling the fucntion findday
You can’t perform that action at this time.
0 commit comments