Sunday, July 19, 2020

Calendar Module-HackerRank Solution

codingclown_hackerank_solution_python
 Calendar Module-HackerRank Solution

 The calendar module allows you to output calendars and provides additional useful functions for them.

class calendar.TextCalendar([firstweekday])

This class can be used to generate plain text calendars.





Sample Code

>>> import calendar
>>> 
>>> print calendar.TextCalendar(firstweekday=6).formatyear(2015)
    

Task

You are given a date. Your task is to find what the day is on that date.

Input Format

A single line of input containing the space separated month, day and year, respectively, in    format.

Constraints

Output Format

Output the correct day in capital letters.

Sample Input

08 05 2015

Sample Output

WEDNESDAY

Explanation

The day on August th  was WEDNESDAY.


Calendar Module Solution


weekday={0:'MONDAY',1:'TUESDAY',2:'WEDNESDAY',3:'THURSDAY',4:'FRIDAY',5:'SATURDAY',6:'SUNDAY'}
import calendar
m=[]
a=list(input().split())  #MM DD YYYY format

day=(calendar.weekday(int(a[2]),int(a[0]),int(a[1]))) #gives input in year,month,day format
print(weekday[day])

Explantion-


Calendar.weekday takes input in year,month,day format. So, we will give our input list a=[08,05,2015] in YYYY, MM, DD format to this function. In order to convert 08 to 8 and 05 to 5 we will typecast all values into int. 

calendar.weekday -returns the day of the week in integer values where 0 is MONDAY and soon..

To print the day name we will make the use of dictionary weekday which we created earlier in the code. 

0 comments:

Post a Comment

Feel free to share your thoughts and suggestion...