forked from mayankchaudhary26/HacktoberFest-Practice-2021
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmonth_calander.py
More file actions
66 lines (40 loc) Β· 1.37 KB
/
month_calander.py
File metadata and controls
66 lines (40 loc) Β· 1.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
month = int(input("give the month: "))
year = int(input("give the year: "))
days_passed = 0
def findLeap(year): # function to check leap year
if(year % 400 == 0):
return 1
if(year % 4 == 0 and year%100 != 0):
return 1
return 0
def daysInMonth(month, year): # function to find days in current month
if(month == 2 and findLeap(year)):
return 29
elif(month == 2):
return 28
elif(month == 4 or month== 6 or month== 9 or month== 11):
return 30
else:
return 31
for current_year in range(1900, year+1): # calculate the total days passed
if(current_year < year):
if(findLeap(current_year)):
days_passed += 366
else:
days_passed += 365
else :
for current_month in range(1, month + 1):
if(current_month < month):
days_passed += daysInMonth(current_month, current_year)
week_day = days_passed % 7 # get the week day
print("\n Calander ")
print("M T W T F S S")
# print("\n--------------------")
print(" " * (week_day), end= "")
for i in range(1, daysInMonth(month, year) + 1):
if(i < 10):
print("0", end="")
if((i + week_day) % 7 == 0):
print(i)
else:
print(i, end =" ")