我寫了這個程序來計算你生活的天數,當你使用當前日期和你的出生日期作爲輸入(不管是哪一個第一,只要它的格式是:y,m,d。我的第一個代碼有史以來,所以它可能是不良的結構,但我想知道爲什麼它返回沒有?爲什麼這個python代碼仍然沒有返回?
def past_presenter(year1,month1,day1,year2,month2,day2):
if year1>year2:
year1,month1,day1,year2,month2,day2 = year2,month2,day2,year1,month1,day1
return year1,month1,day1,year2,month2,day2
else:
if month1>month2:
year1,month1,day1,year2,month2,day2 = year2,month2,day2,year1,month1,day1
return year1,month1,day1,year2,month2,day2
else:
if day1>day2:
year1,month1,day1,year2,month2,day2 = year2,month2,day2,year1,month1,day1
return year1,month1,day1,year2,month2,day2
def absolute(y,m,d):
if y<0:
y=y*-1
if m<0:
m=m*-1
if d<0:
d=d*-1
return y,m,d
def days(year1,month1,day1,year2,month2,day2):
y=year2-year1
m=month2-month1
d=day2-day1
y,m,d = absolute(y,m,d)
days=d+(m*30)+(y*30*12)
return days
def daysBetweenDates(year1,month1,day1,year2,month2,day2):
year1,month1,day1,year2,month2,day2 = past_presenter(year1,month1,day1,year2,month2,day2)
dd = days(year1,month1,day1,year2,month2,day2)
return dd
print daysBetweenDates(2017,2,10,1980,1,1)
Aaaaand怎麼樣的飛躍天?不要推出自己的日期計算。只需使用'datetime'。 https://docs.python.org/3.6/library/datetime.html –
更不用說,不是每個月都有30天..... –
@JackManey我把這段代碼寫成了練習。我的問題是,我一直沒有輸出。即使當我打電話功能'天(1880,12,30,1990,1,1)'仍然不工作 – KOOLz