1 Star 0 Fork 0

wdc/Python001

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
Day_of_week.py 1.02 KB
一键复制 编辑 原始数据 按行查看 历史
Vishal Naik 提交于 2020-06-23 15:07 . get the input from the user
# 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) )
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/ijiwei/Python001.git
git@gitee.com:ijiwei/Python001.git
ijiwei
Python001
Python001
master

搜索帮助