輸入日期判斷這天是一年中第幾天

2021-10-05 15:00:18 字數 1093 閱讀 4291

判斷這天是一年中第幾天

nonleap =[0

,31,28

,31,30

,31,30

,31,31

,30,31

,30,31

]leap =[0

,31,29

,31,30

,31,30

,31,31

,30,31

,30,31

]sum=0

date =

input

("請輸入想要查詢的年月日,格式如:***x-xx-xx\n"

)date = date.split(

"-")

ifint

(date[0]

)<0:

print

("日期輸入錯誤"

)elif

int(date[1]

)<=0or

int(date[1]

)>12:

print

("日期輸入錯誤"

)elif

(int

(date[0]

)%4==

0and

int(date[0]

)%100!=0)

orint

(date[0]

)%400==0:

for x in

range

(int

(date[1]

)):sum

+= leap[x]

print

("這天是這年第{}天"

.format

(sum

+int

(date[2]

)))else

:for x in

range

(int

(date[1]

)):sum

+= nonleap[x]

print

("這天是這年第{}天"

.format

(sum

+int

(date[2]

)))

Python程式設計判斷這天是這一年第幾天的方法示例

本文例項講述了python程式設計判斷這天是這一年第幾天的方法。分享給大家供大家參考,具體如下 題目 輸入某年某月某日,判斷這一天是這一年的第幾天?實現 year int input 請輸入年 month int input 請輸入月 day int input 請輸入天 sum day days ...

1101 一年中的第幾天

給出某個日期,判斷這是當年的第幾天,每年的1月1日是第1天,非閏年年份的12月31日是第365天。輸入的第乙個數為n,後接n個日期。日期用3個正整數按順序表示年月日,中間用 連線。若輸入的日期為錯誤,則輸出 error date 否則輸出這個日期是本年的第幾天。每個日期對應一行輸出。92010 01...

用C程式設計計算某日期是一年中第幾天

1.輸入年月日,編寫程式計算所輸日期是當年的第幾天 2.已知列車隔日發車,且1 1 2006不發車 無ticket 如果所輸入資料在此日期之後,則輸出有沒有車票,否則僅輸出上一步結果。month date year is which day of the year is there a ticket...