Skip to content

Commit a152a39

Browse files
Merge pull request #750 from Monsieurvishal/patch-1
get the input from the user
2 parents 786de03 + b396208 commit a152a39

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

Day_of_week.py

+13-4
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,23 @@
11
# Python program to Find day of
22
# the week for a given date
3+
import re #regular expressions
34
import calendar #module of python to provide useful fucntions related to calendar
45
import 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

0 commit comments

Comments
 (0)