Skip to content

Instantly share code, notes, and snippets.

@abhisheks-12
Last active December 6, 2021 10:26
Show Gist options
  • Save abhisheks-12/938dd465ff3e41e441f824cff27d9518 to your computer and use it in GitHub Desktop.
Save abhisheks-12/938dd465ff3e41e441f824cff27d9518 to your computer and use it in GitHub Desktop.
import calendar
from collections import Counter
# shaikh gandhnar aahe kuthe tari jara try karun bgh :)
def using_calender(year,month,date):
# if (year % 4 == 0) and (year % 100 != 0):
# year = 2
# print(year)
# elif (year % 4 == 0) and (year % 100 == 0) and (year % 400 == 0):
# year = 2
# print(year)
# else:
# print(year)
if calendar.isleap(year):
month = 2
else:
month
# print date
print(calendar.month(year,month))
# last 7 days
days = []
cal = calendar.Calendar()
for day in cal.monthdatescalendar (year,month):
days.append(day)
print(days[-1])
# most frequent day
my_list1 = []
for i in cal.itermonthdays2(year, month):
if i[0] == 0:
pass
else:
my_list1.append(str(i[1]))
most_frequentday = ""
int_values = []
for i in my_list1:
int_values.append(int(i))
num = Counter(int_values)
num = num.most_common(1)[0][0]
if num == 0:
most_frequentday = "Monday"
if num == 1:
most_frequentday = "Tuesday"
if num == 2:
most_frequentday =="Wednesday"
if num == 3:
most_frequentday = "Thursday"
if num == 4:
most_frequentday = "Friday"
if num == 5:
most_frequentday = "Saturday"
if num == 6:
most_frequentday ="Sunday"
print(most_frequentday);
year = 2022
month = 10
date = 11
using_calender(year,month,date)
# Updated solution
#################################################################################################################################
import calendar
from collections import Counter
# shaikh gandhnar aahe kuthe tari jara try karun bgh :)
def using_calender(year,month,date):
# if (year % 4 == 0) and (year % 100 != 0):
# year = 2
# print(year)
# elif (year % 4 == 0) and (year % 100 == 0) and (year % 400 == 0):
# year = 2
# print(year)
# else:
# print(year)
if calendar.isleap(year):
month = 2
else:
month
# print date
print(calendar.month(year,month))
# last 7 days
days = []
cal = calendar.Calendar()
for day in cal.monthdatescalendar (year,month):
days.append(day)
print(days[-1])
# most frequent day
my_list1 = []
for i in cal.itermonthdays2(year, month):
if i[0] == 0:
pass
else:
my_list1.append(str(i[1]))
most_frequentdays = []
int_values = []
for i in my_list1:
int_values.append(int(i))
num = Counter(int_values)
num = num.most_common(1)[0][0]
if num == 0:
most_frequentdays.append("Monday")
if num == 1:
most_frequentdays.append("Tuesday")
if num == 2:
most_frequentdays.append("Wednesday")
if num == 3:
most_frequentdays.append("Thursday")
if num == 4:
most_frequentdays.append("Friday")
if num == 5:
most_frequentdays.append("Saturday")
if num == 6:
most_frequentdays.append("Sunday")
unique_day = tuple(most_frequentdays)
print(unique_day[0])
year = 2020
month = 10
date = 11
using_calender(year,month,date)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment