0% found this document useful (0 votes)
31 views2 pages

Python Hands-On

This function checks if a year is a leap year, prints a calendar for a given month and year, finds the last Monday of the month, creates a list of dates for that week, and prints the day of the week that the month starts on.

Uploaded by

Aman Pradhan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
31 views2 pages

Python Hands-On

This function checks if a year is a leap year, prints a calendar for a given month and year, finds the last Monday of the month, creates a list of dates for that week, and prints the day of the week that the month starts on.

Uploaded by

Aman Pradhan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

import calendar

import datetime
def checkLeapYear (year):
if (year % 4) == 0:
if (year % 100) == 0:
if (year % 400) == 0:
return 1
else:
return 0
else:
return 1
else:
return 0

def usingcalendar (datetuple):


year = datetuple[0]
leap= checkLeapYear (year)
if leap== 1:
month = 2
else:
month=datetuple[1]
print (calendar. month (year, month))

m = calendar.monthcalendar (year, month)


mondays = [week [0] for week in m if week [0]>0]
day= mondays [-1]
lst = []
MONTH= month
YEAR = year

for i in range(7):
d= datetime.date (year, month, day)
lst.append(d)
if (leap == 1) and (month == 2):
if(day== 29):
day = 0
if(month== 12):
month = 1
year= year + 1
else:
month= month + 1
elif (leap == 0) and (month == 2):
if(day == 28):
day = 0
if(month== 12):
month = 1
year = year + 1
else:
month=month + 1
else:
if((month == 1) or (month== 3) or (month==5)or(month ==7) or (month==8)
or(month ==10)or(month == 12)) and (day== 31):
day= 0
if(month== 12):
month = 1
year = year + 1
else:
month= month + 1
elif((month == 4) or (month == 6) or (month == 9) or (month == 11)) and
(day == 30):
day = 0
if(month== 12):
month = 1
year= year + 1
else:
month= month + 1
day= day + 1
print(lst)
a = (datetime.datetime(YEAR, MONTH,1))
starting_day = a.strftime ("%A")
days = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday",
"Sunday" ]
count= [4 for i in range(0,7)]
pos=-1
for i in range(0,7):
if (starting_day == days[i]):
pos= i
break
print(days [pos])

You might also like