BetaCodeShareBeta

by Code Solutions Project

Simple solutions for common problems

Description:Insert the year the month and the day and recieve the week day
Python
Landon19
"""
@author: @lLandon19
"""
#Simple way to see if a year is a leap year
def leapyear(year):
    if(year%400==0):
        return True
    if(year%100==0):
        return False
    if(year%4==0):
        return True
    else:
        return False

def weekday(Year,Month,Day):
    #List with values for different months
    auxlist = (0,3,3,6,1,4,6,2,5,7,3,5)
    if(leapyear(Year) and Month<3):
        C = 0
    else:
        C = 1
    D=auxlist[Month-1] + C
    Result = round(((Year-1)+((Year-1)/4-3*((Year-1)/100+1)/4)+D+Day)%7)
    #Sunday=0, Monday=1 ...
    print(Result)

Input example

2018
12
9

Output example

0
×Oh snap! Something wrong