Created
May 21, 2013 14:02
-
-
Save grimmo/5620007 to your computer and use it in GitHub Desktop.
Day of the week
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python | |
| COMMON_YEAR_DAYS =365 | |
| LEAP_YEAR_DAYS = 366 | |
| days_in_months = {0:0,1:31,2:28,3:31,4:30,5:31,6:30,7:31,8:31,9:30,10:31,11:30,12:31} | |
| giorni = ['monday','tuesday','wednsday','thursday','friday','saturday','sunday'] | |
| def is_it_leap(year): | |
| return year%4 == 0 and not year%100 == 0 or year%400 ==0 | |
| def day_of_the_week(year,month,day): | |
| distance = 0 | |
| for current_year in range(1,year): | |
| if is_it_leap(current_year): | |
| distance+=LEAP_YEAR_DAYS | |
| else: | |
| distance+=COMMON_YEAR_DAYS | |
| for current_month in range(0,month): | |
| if is_it_leap(year) and current_month == 2: | |
| distance+=days_in_months[current_month]+1 | |
| else: | |
| distance+=days_in_months[current_month] | |
| distance+=day-1 | |
| return distance | |
| if __name__ == "__main__": | |
| giorno = int(raw_input('Giorno:')) | |
| mese = int(raw_input('Mese:')) | |
| anno = int(raw_input('Anno:')) | |
| dow = day_of_the_week(anno,mese,giorno) | |
| print "Distanza in giorni: %i" % dow | |
| print "Giorno della settimana: %s" % giorni[dow%7] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment