标题
python编写一个输入日期,计算这是一年的第几天
year = int(input("please input the year you need to check: "))
month = int(input("please input the month you need to check: "))
while 12 < month or month < 1:
print(“please input true month!”)
month = int(input("please input the month you need to check: "))
day = int(input("please input the day you need to check: "))
while day > 31 or day < 1:
print(“please input true days!”)
day = int(input("please input the month you need to check: "))
A = 0 # A用来叠加月份
i = 0 # i 循环中介
list_days = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31] # 非闰年的列表,方便后面按顺序访问,叠加。
if year % 400 == 0 or (year % 4 == 0 and year % 100 != 0): # 判断闰年
list_days[1] = 29
while i < month - 1:
A = A + list_days[i]
i += 1
print("this day is the")
print(A+day)
else:
while i < month - 1:
A = A + list_days[i]
i += 1
print(“this day is the”)
print(A+day)