1. 程式人生 > 實用技巧 >分別輸入某年某月某日,判斷這一天是這一年的第幾天?(考慮閏年)

分別輸入某年某月某日,判斷這一天是這一年的第幾天?(考慮閏年)

#方法一:
# year = int(input("請輸入年:"))
# month = int(input("請輸入月:"))
# day = int(input("請輸入日:"))
# if month == 1:
# count = day
# elif month == 2:
# count = 31 + day
# elif (month >= 3) and ((year % 4 == 0 and year % 100 != 0) or year % 400 == 0):
# if month == 3:
# count = 31 + 29 + day
# if month == 4:
# count = 31 + 29 + 31 + day
# if month == 5:
# count = 31 + 29 + 31 + 30 + day
# if month == 6:
# count = 31 + 29 + 31 + 30 + 31 + day
# if month == 7:
# count = 31 + 29 + 31 + 30 + 31 + 30 + day
# if month == 8:
# count = 31 + 29 + 31 + 30 + 31 + 30 + 31 + day
# if month == 9:
# count = 31 + 29 + 31 + 30 + 31 + 30 + 31 + 31 + day
# if month == 10:
# count = 31 + 29 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + day
# if month == 11:
# count = 31 + 29 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + day
# if month == 12:
# count = 31 + 29 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + 30 + day
# else:
# if month == 3:
# count = 31 + 28 + day
# if month == 4:
# count = 31 + 28 + 31 + day
# if month == 5:
# count = 31 + 28 + 31 + 30 + day
# if month == 6:
# count = 31 + 28 + 31 + 30 + 31 + day
# if month == 7:
# count = 31 + 28 + 31 + 30 + 31 + 30 + day
# if month == 8:
# count = 31 + 28 + 31 + 30 + 31 + 30 + 31 + day
# if month == 9:
# count = 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + day
# if month == 10:
# count = 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + day
# if month == 11:
# count = 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + day
# if month == 12:
# count = 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + 30 + day
#
# print(year,'年第' + str(count) + '天')

#方法二:
# year = int(input("請輸入年:"))
# month = int(input("請輸入月:"))
# day = int(input("請輸入日:"))
# list = [31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335, 366]
#
# if month == 1:
# count = day
# if (year % 4 == 0 and year % 100 != 0) or year % 400 == 0:
# if month > 1 and month <= 12:
# count = list[month - 2] + day
# else:
# if month > 1 and month <=12:
# count = list[month - 2] + day - 1
# print('第' + str(count) + '天')