Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # 1 Jan 2001 was Monday
- week_day = 1 # 1 based indexing, so 1 -> Monday, 2 -> Tuesday, ..., 7 -> Sunday
- month_days = 31 # January has 31 days
- month = 1 # 1 -> January, 2 -> February, ..., 12 -> December
- year = 2001
- req_number_of_sundays = 0
- while year != 2101:
- if (month % 2 == 1 and month <= 7) or (month % 2 == 0 and month > 7):
- month_days = 31
- else:
- if month == 2:
- if year % 4 == 0:
- month_days = 29
- else:
- month_days = 28
- else:
- month_days = 30
- for day in range(1, month_days + 1):
- if week_day > 7:
- week_day = 1
- if day == 1 and week_day == 7:
- req_number_of_sundays += 1
- week_day += 1
- month += 1
- if month > 12:
- month = 1
- year += 1
- print("The number of Sundays are: " + str(req_number_of_sundays))
- # Output:
- #
- # The number of Sundays are: 172
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement