File tree 1 file changed +13
-4
lines changed
1 file changed +13
-4
lines changed Original file line number Diff line number Diff line change 1
1
# Python program to Find day of
2
2
# the week for a given date
3
+ import re #regular expressions
3
4
import calendar #module of python to provide useful fucntions related to calendar
4
5
import datetime # module of python to get the date and time
5
6
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
6
11
7
- def findDay (date ):
12
+ def find_day (date ):
8
13
born = datetime .datetime .strptime (date , '%d %m %Y' ).weekday () #this statement returns an integer corresponding to the day of the week
9
14
return (calendar .day_name [born ]) #this statement returns the corresponding day name to the integer generated in the previous statement
10
15
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
+
11
23
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