【Python】寫一個程序,判斷給定年份是否爲閏年。

寫一個程序,判斷給定年份是否爲閏年。

temp = input('請輸入一個年份,判斷是否爲閏年:')
while not temp.isdigit():
    temp = input('數據錯誤,請再次輸入:')
LeapYear = int(temp)
if ((LeapYear //4 == LeapYear /4) & ~(LeapYear //100 != LeapYear /100)) | (LeapYear //400 == LeapYear /400):
    print(temp + '年是閏年')
else:
    print(temp + '年不是閏年')

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章