Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Ask the user to type in a year ( < 2 0 0 0 ) and a month ( 1 - 1 2 ) .

Ask the user to type in a year (<2000) and a month (1-12). Your program should print out that month calendar.
- reuse the code above if applicable.
can you help i want contiue my code is stop calculating the correct data after 1900
# use list or tuple for the given data
month_name =["January", "February", "March", "April", "May", "June",
"July", "August", "September", "Octber","November", "December" ]
week_day =["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"]
month_day =[31,28,31,30,31,30,31,31,30,31,30,31]
# Given 2000 Jan. 1 falls on a Sat.
yyyy =2000
offset_0=6
# Code here
def is_leap_year(year):
"""Checks if it's a leap year."""
return (year %4==0 and year %100!=0) or (year %400==0)
def days_in_month(year, month):
"""Gives the number of days in a month."""
if month ==2:
return 29 if is_leap_year(year) else 28
elif month in {4,6,9,11}:
return 30
else:
return 31
def weekday_of_first_day(year, month):
"""Returns the weekday (0- Monday, 6- Sunday) of the first day of the month."""
days_since_2000=0
for y in range(year<2000):
days_since_2000+=366 if is_leap_year(y) else 365
for m in range(1, month):
days_since_2000+= days_in_month(year, m)
return (days_since_2000+1)%7 # +1 because December 1,1990 is a Saturday
def print_month_calendar(year, month):
"""Prints the calendar of a given month."""
# Validate input
if year >=2000:
print("Please enter a year prior to 2000.")
return
if month <1 or month >12:
print("Please enter a valid month (1-12).")
return
if year <2000 and month ==12:
first_day_of_december = weekday_of_first_day(year, month)
if first_day_of_december !=6: # 6= Saturday
days_to_add =(6- first_day_of_december)%7
month +=1
if month >12:
month =1
year +=1
print_month_calendar(year, month)
return
print(f"{month_name[month -1]}{year}")
# Print the calendar
print(" Su Mo Tu We Th Fr Sa")
first_day = weekday_of_first_day(year, month)
for _ in range(first_day):
print("", end="")
for day in range(1, days_in_month(year, month)+1):
print(f"{day:2}", end="")
if (first_day + day)%7==0 or day == days_in_month(year, month):
print()
# Ask for user input
year = int(input("Enter a year (<2000): "))
month = int(input("Enter a month (1-12): "))
# Print the calendar
print_month_calendar(year, month)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Nested Relations And Complex Objects In Databases Lncs 361

Authors: Serge Abiteboul ,Patrick C. Fischer ,Hans-Jorg Schek

1st Edition

3540511717, 978-3540511717

More Books

Students also viewed these Databases questions

Question

Ask the user to type in a year ( Answered: 1 week ago

Answered: 1 week ago