We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
- Prepare
- Python
- Date and Time
- Calendar Module
- Discussions
Calendar Module
Calendar Module
+ 0 comments import calendar # collect information about mm, dd, and yy while converting into integers mm, dd, yy = (int(i) for i in input().split()) # Returns the day of the week. Monday is zero. weekday = calendar.weekday(yy,mm,dd) # day_name takes an array and returns the name of the weekday associated with the value inside of our array. # It can not return multiple weekdays. # I.E our array cannot have multiple values inside of it print(calendar.day_name[weekday].upper())
+ 1 comment Another oneliner, (year > 2000)
print( (lambda m, d, y: ['SATURDAY', 'SUNDAY', 'MONDAY', 'TUESDAY', 'WEDNESDAY', 'THURSDAY', 'FRIDAY'][int((int(d)+[0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365][int(m) - 1]-(not int(y)%4 and int(m)<3)+(int(y)-2000)*365.25)%7)])(*input().split()) )
+ 0 comments Enter your code here. Read input from STDIN. Print output to STDOUT
import calendar import datetime date_time = input().split() month = date_time[0] day = date_time[1] year = date_time[2]
day_number = calendar.weekday(int(year), int(month), int(day)) day_name = calendar.day_name[day_number] print(day_name.upper())
+ 0 comments import calendar mm, dd, yy = map(int, input().split()) print(calendar.day_name[calendar.weekday(yy,mm,dd)].upper())
+ 0 comments ---------------------------------------MY SOLUTION--------------------------------------
- Assign values to three vars (day, month, year) using string index.
- Store the calendar in a variable. cal = calendar.weekday(year, month, day)
- Create a list to hold days of the week starting from monday. (0th element is monday).
- Iterate over the list elements and print out the respective list element which is equal to the value in cal variable https://colab.research.google.com/drive/12QEMyeN8SyuFAxjwgKdLcqMm__0gV5rT?usp=sharing
Load more conversations
Sort 552 Discussions, By:
Please Login in order to post a comment