class Weekday: def getDay(self, month, day, year): # count the number of days first # then calculate the weekday by diviing 7 days_for_year = (year - 1990)*365 if year > 1996: days_for_year += 2 elif year == 1992: if month > 2 or (month == 2 and day == 29): days_for_year += 1 elif year == 1996: if month >2 or (month == 2 and day == 29): days_for_year += 1 elif year > 1992 and year < 1996: days_for_year += 1 months = [0,31, 28, 31,30,31,30,31,31,30,31,30,31] days_for_month = 0 for i in range(month): days_for_month += months[i] days_for_day = day total_days = days_for_day + days_for_month + days_for_year weekday = total_days % 7 return weekday """ the better way is """ class Weekday: def getDay(self, month, day, year): days = (year-1990) * 365 if year > 1992: days += 1 if year > 1996: days += 1 months = [0,31,28,31,30,31,30,31,31,30,31,30,31] for i in range(month): if (i == 2 and (year == 1992 or year == 1996)): days += 1 days += months[i] days += day weekday = days % 7 return weekday ~ ''' Given that January 1, 1990 falls on a Monday, determine which weekday a given date (restricted to the years 1990-1999) falls on. The program will take as input three integers representing a valid month, day, and year, from the years 1990-1999. The output will be a string containing a case sensitive day of the week : (Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday) Here are the number of days for each month in 1990-1999 : (Jan, Mar, May, Jul, Aug, Oct, Dec) = 31; (Apr, Jun, Sep, Nov) = 30; (Feb)=28 except on 1992, 1996 (Feb)=29 (leap year) NOTE : You are not allowed to use any external libraries for this problem (ie no import statements) Here is the method signature : public String getDay(int month, int day, int year); We will check to make sure the input to this problem is valid. (ie date validity, year restriction, etc) Example : Input : 4 26 1999 Output : Monday'''
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question