Untitled
unknown
plain_text
a year ago
2.2 kB
1
Indexable
Never
import datetime, calendar def daysInMonth(month, year): # 30 days: Sept, Apr, Jun, Nov # 31 days: Jan, Mar, May, Jul, Aug, Oct, Dec # 28 days: Feb (sometimes 29) need to worry about leap years if month in [9, 4, 6, 11]: return 30 elif month in [1, 3, 5, 7, 8, 10, 12]: return 31 else: if year % 4 == 0 and (year % 100 != 0 or year % 400 == 0): return 29 else: return 28 def firstDayMonth(month, year): days = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"] date = datetime.date(year, month, 1) day = date.weekday() return day def printCalendar(day, month, year, firstDay): monthName = calendar.month_name[month] print(f"{monthName}, {year}") print("M\t T\t W\t T\t F\t S\t S") print("\t " * firstDay, end = "") count = firstDay + 1 # +1 for our sakes for i in range(1, daysInMonth(month, year) + 1): if i == day: print(f">{str(i).zfill(2)}<", end = "") # forces the date to be two digits long elif i == day - 1: print(str(i).zfill(2), end = "\t") else: print(str(i).zfill(2), end = "\t ") # forces the date to be two digits long if count == 7: print("\n", end = "") count = 1 else: count += 1 ##month = -1 ##year = -1 ## ##while month < 1 or month > 12: ## print("Must be between 1 and 12") ## month = input("Enter a month") ## ## try: ## month = int(month) ## except: ## month = -1 ## print("Must be an integer") ## ##while year < 1 or year > 9999: ## print("Must be between 1 and 9999") ## year = input("Enter a month") ## ## try: ## year = int(year) ## except: ## year = -1 ## print("Must be an integer") ##print(daysInMonth(4, 2024)) ##print(daysInMonth(2, 2024)) ##print(daysInMonth(2, 2000)) ##print(daysInMonth(2, 1900)) ##print(daysInMonth(7, 2023)) days = daysInMonth(11, 2006) first = firstDayMonth(11, 2006) printCalendar(19, 11, 2006, first)