代码拉取完成,页面将自动刷新
# Python program to Find day of
# the week for a given date
import re #regular expressions
import calendar #module of python to provide useful fucntions related to calendar
import datetime # module of python to get the date and time
def process_date(user_input):
user_input=re.sub(r"/", " ", user_input) #substitute / with space
user_input=re.sub(r"-", " ", user_input) #substitute - with space
return user_input
def find_day(date):
born = datetime.datetime.strptime(date, '%d %m %Y').weekday() #this statement returns an integer corresponding to the day of the week
return (calendar.day_name[born]) #this statement returns the corresponding day name to the integer generated in the previous statement
#To get the input from the user
#User may type 1/2/1999 or 1-2-1999
#To overcome those we have to process user input and make it standard to accept as defined by calender and time module
user_input=str(input("Enter date "))
date=process_date(user_input)
print("Day on " +user_input + " is "+ find_day(date) )
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。