這是我的代碼:代碼檢查閏年和月計數無天的
def cal(month):
if month in ['January', 'march','may','july','august','oct','dec']:
print ("this month has 31 days")
elif month in ['april','june','sept','nov']:
print ("this month has 30 days")
elif month == 'feb' and leap(year)== True:
print ("this month has 29 days")
elif month == 'feb' and leap(year) == False:
print ("this month has 28 days")
else:
print ("invalid input")
def leap(year):
if (year % 4== 0) or (year % 400 == 0):
print ("its a leap year!")
else:
print ("is not a leap year")
year = int(input('type a year: '))
print ('you typed in :' , year)
month = str(input('type a month: '))
print ('you typed in :', month)
cal(month)
leap(year)
我收到的輸出:
type a year: 2013
you typed in : 2013
type a month: feb
you typed in : feb
is not a leap year
is not a leap year
invalid input
is not a leap year
爲什麼我沒有得到輸出如果是28天的月份還是29天,那麼在feb中的天數是多少?
爲什麼我會得到無效的輸入部分,即使它是一個其他的?
'leap'的返回值是'None'。 'None == True'和'None == False'都是錯誤的。 – vaultah
1900年不是閏年。你的測試會假設它是。 –
謝謝隊友。解決了它。 :) – Teejay