判断一个用户输入的日期是不是闰年. Python 代码

该博客展示了一个Python程序,用于接收用户输入的日期,并判断该年份是否为闰年。程序要求用户输入的日期格式为Year-Month-day,并会提示用户确认输入的日期,对不规范的日期格式给出错误提示。
摘要由CSDN通过智能技术生成
'''获取键盘中输入的日期,提取年份,然后判断这个年份是不是闰年'''
import datetime,time,types
global format_date
format_date="%Y-%m-%d"
def isLeap_year():
    year=dateConfirmation()
    print 'year =',year
    if type(year) is types.IntType:
        print 'yearInt', year
        judge(year)
    else:
        print year,'is not a Integer'
        year = int(year)
        judge(year)
    return True


# 输入数据
def input_date():
    global date
    date = raw_input("please enter date, format is Year-Month-day:")
    return date
# 处理输入的日期
def dateConfirmation():
    try:
        date1= input_date()
        print '你输入的日期是:',date1,'请确认'
        datetime.datetime.strptime(date1,format_date)
        year = time.strptime(date1,"%Y-%m-%d")
        newYear= "%s" %year.tm_year
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值