python輸入年份月份輸出天數(shù) python正則表達式辨別輸入日期規(guī)范是什么?
python正則表達式辨別輸入日期規(guī)范是什么?1. Python正則表達式的輸入日期規(guī)范如下:year,month,day=Eval(input(“please input year,month,da
python正則表達式辨別輸入日期規(guī)范是什么?
1. Python正則表達式的輸入日期規(guī)范如下:
year,month,day=Eval(input(“please input year,month,day,separated by comma”)
months=[31,28,31,30,31
]if(year%4==0 and year 0!=0)或(年@0==0):
months[1]=29#在閏年,二月最多有29天
如果month<1或month>12:
print(“l(fā)egal month”
elif day<1或day>months[month 1
]print(“l(fā)egal day”
else:
print(“l(fā)egal month”
2)。代碼:
3。結(jié)果:
Python:輸入年月日判斷是此年的第多少天?
導(dǎo)入日期時間
y=int(輸入(“請輸入4位數(shù)字年份:”)get year
m=int(輸入(“請輸入月份:”)get month
D=int(輸入(“請輸入哪一天:”)get day
targetday=datetime.date日期(年,月,d) #將輸入的日期格式化為標準日期
daycount=targetday-datetime.date日期( targetDay.year公司-1,12,31)#減去上一年的最后一天
打?。?s是%s年的第%s天?!?(targetDay,ydayCount.days天))