Calculate the day of the week from a random input date (based on January 1, 1900)

It is known that January 1, 1900 is Monday, and the user randomly inputs the year, month and day to calculate the day of the week

The code is as follows (not improved), welcome criticism and correction

year=int(input('year'))
month=int(input('month'))
day=int(input('day'))
if year >=1900:#大于等于1900
    ryear =1900
    sum =0
    while ryear < year:#1901
        if ((ryear % 4 == 0) and (ryear %100 !=0))or(ryear % 400 == 0):#云年
            sum+=2
        else:
            sum +=1 
        ryear +
     =1 #Calculate month move 
    mon = month
    r_month = 1
     while r_month < month: #Calculate to the 1st of mon month 
        if r_month in [1,3,5,7,8,10,12 ]:
            sum +=3
            sum = sum % 7
        elif r_month in [4,6,9,11]:
            sum +=2
        else:
            if (year % 4 == 0 and year %100 != 0) or (ryear % 400 == 0):
                sum +=1
            else:
                sum +=0
        r_month +=1
     #Calculate day 
    sumday = day -1 
    sum += sumday
    sum = sum % 7
     #judgment based on movement 
    if sum ==1 :
         print ( ' week 2 ' )
     elif sum ==2 :
         print ( ' week 3 ' )
     elif sum ==3 :
         print ( ' week 4 ' )
     elif sum ==4 :
         print ( ' Week 5 ' )
     elif sum ==5 :
         print ( ' Week 6 ')
     elif sum ==6 :
         print ( ' week 7 ' )
     else :
         print ( ' week 1 ' )
 else : #calculate less than 1990 
    ye = year
    year +=1
    sum = 0
    while year<1900:
        if (year % 4 == 0 and year %100 !=0) or(year % 400 == 0):#闰年
            sum+=2
        else:
            sum +=1 
        year +=1
     #Calculate month move 
    mo= month
    month =month+1
     while month <=12: #Calculate to the 1st of mon month 
        if month in [1,3,5,7,8,10,12 ]:
            sum +=3
        elif month in [4,6,9,11]:
            sum +=2
        else:
            if (year % 4 == 0 and year %100!=0) or(year % 400 == 0):
                sum +=1
            else:
                sum +=0
        month +=1
     #Calculate days 
    if mo in [1,3,5,7,8,10,12 ]:
        sum += 31-day+1
    elif mo in [4,6,9,11]:
        sum += 30-day+1
    else:
        if (year % 4 == 0 and year %100 !=0) or (year % 400 == 0):
            sum += 29-day+1
        else:
            sum += 28-day+1 
    sum = sum % 7
     #judgment based on movement 
    if sum ==1 :
         print ( ' week 7 ' )
     elif sum ==2 :
         print ( ' week 6 ' )
     elif sum ==3 :
         print ( ' week 5 ' )
     elif sum ==4 :
         print ( ' week 4 ' )
     elif sum ==5 :
         print (' Week 3 ' )
     elif sum ==6 :
         print ( ' Week 2 ' )
     else :
         print ( ' Week 1 ' )
 print ( ' game over ' )
Day of the week

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325012798&siteId=291194637