python question writing example | Question: Enter a certain year, a certain month and a certain day, and determine the day of the year that this day is.

year = int(input("the year is:"))
month = int(input("the month is:"))
day = int(input("the day is:"))
total_day = 0
# Determine if it is a leap year
if year % 400 ==0:
    t = 1
    print("%d is a leap year"%year)
elif year%100!=0 and year%4==0:
    print("%d is a leap year"%year)
    t = 1
else:
    print("%d is't a leap year"%year)
    t = 0

# Determine the month
if t == 1:
    list_month = [0,31,29,31,30,31,30,31,31,30,31,30,31]
else:
    list_month = [0,31,28,31,30,31,30,31,31,30,31,30,31]

for i in range(0,month):
    total_day += list_month[i]
print("It's the %d day of %d"%(total_day+day,year))

おすすめ

転載: blog.csdn.net/zzztutu/article/details/126184053