Python 7 Levels, L3, Unit 28, Perpetual Calendar I

Powered By EmbedPress

Exercise 1:

sum_day = 0
for year in range(1900,2019):#days from Jan. 1, 1900 to Dec. 31, 2018
    if (year%4==0 and year%100!=0) or (year%400==0):
        sum_day += 366
    else:
        sum_day +=365
sum_day+=1#add Jan. 1 2019
print(sum_day)

Exercise 2:

sum_day = 0
for year in range(1900,2019):#days from Jan. 1, 1900 to Dec. 31, 2018
    if (year%4==0 and year%100!=0) or (year%400==0):
        sum_day += 366
    else:
        sum_day +=365
for month in range(1,10):#days from Jan. 1, 2019 to Sep. 30, 2019
    if month == 2:
        if (2019%4==0 and 2019%100!=0) or (2019%400==0):
            sum_day +=29
        else:
            sum_day+=28
    elif month == 4 or month == 6 or month ==9 or month == 11:
        sum_day += 30
    else:
        sum_day += 31
sum_day+=1#add Oct. 1, 2019
print(sum_day)

Exercise 3:

year_in = int(input("Please input year:"))
month_in = int(input("Please input month:"))
sum_day = 0
for year in range(1900,year_in):#days from Jan. 1, 1900 to Dec. 31, year_in -1
    if (year%4==0 and year%100!=0) or (year%400==0):
        sum_day += 366
    else:
        sum_day +=365
for month in range(1,month_in):#days from Jan. 1, year_in to month_in-1
    if month == 2:
        if (year_in%4==0 and year_in%100!=0) or (year_in%400==0):
            sum_day +=29
        else:
            sum_day+=28
    elif month == 4 or month == 6 or month ==9 or month == 11:
        sum_day += 30
    else:
        sum_day += 31
sum_day+=1#add month_in first day
print("Jan. 1, 1900 - Month",month_in,"Day first Year",year_in,",total there are",sum_day,"days")

dahan1999

1 Comment

Leave a Reply

Your email address will not be published. Required fields are marked *

Related Posts