我期待從上面的代碼輸出一些數字,但我沒有得到它。 我是python的新手,但開始使用PHP進行編碼。 很抱歉,如果我去錯了一些where.thanks我的代碼沒有給出輸出,我期望有一些數字
# By Websten from forums
#
# Given your birthday and the current date, calculate your age in days.
# Compensate for leap days.
# Assume that the birthday and current date are correct dates (and no time travel).
# Simply put, if you were born 1 Jan 2012 and todays date is 2 Jan 2012
# you are 1 day old.
#
# Hint
# A whole year is 365 days, 366 if a leap year.
def nextDay(year, month, day):
"""Simple version: assume every month has 30 days"""
if day < 30:
return year, month, day + 1
else:
if month == 12:
return year + 1, 1, 1
else:
return year, month + 1, 1
def daysBetweenDates(year1, month1, day1, year2, month2, day2):
"""Returns the number of days between year1/month1/day1
and year2/month2/day2. Assumes inputs are valid dates
in Gergorian calendar, and the first date is not after
the second."""
num = 0
# YOUR CODE HERE!
yearx = year1
monthx = month1
dayx = day1
while ((year2 >= year1) and (month2 >= month1) and (day2 >= day1)) :
yearx,monthx,dayx = nextDay(yearx,monthx,dayx)
num = num + 1
num = '5'
return num
print daysBetweenDates(2012,9,30,2012,10,30)
你的程序被關閉陷入無限循環。 –
您不會更改'year2','month2',或'day2'或'year1','month1'或'day',所以您的while循環永遠不會終止。 – thegrinner
'year2 <= 2012和month1 <= 9和day1 <= 30'然後它在某個月份1 = 10它應該停止。 –