Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

This code keeps printing the month wrong. Can you please fix this. Write in python. month_list = ['january', 'february', 'march', 'april', 'may', 'june', 'july', 'august',

This code keeps printing the month wrong. Can you please fix this. Write in python.

month_list = ['january', 'february', 'march', 'april', 'may', 'june', 'july', 'august', 'september', 'october', 'november', 'december']

days_in_month = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]

days_of_week = ['Su', 'Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa']

def calendar(month, year):

# I first wanted to check if the year is a leap year, and if so, modify the days in feb

if is_leap(year):

days_in_month[1] = 29

# Now i set variables to values within my lists based of input data for year and month

month_corrected = month_list[month-1]

num_days = days_in_month[month-1]

# Now I figure out what my start date is for the given month of the year

start_pos = num_days % 7

# Begin by printing the month and year

print(month_corrected[:3], year)

# Print the days of the week for my calendar

print(' '.join(['{0:<2}'.format(w) for w in days_of_week]))

# Print a blank space on the days before my start day variable

print('{0:>3}'.format('')*start_pos, end='')

# Begin looping through the number of days in the month starting with my start day

for day in range(1, num_days+1):

# Print day

print('{0:<3}'.format(day), end='')

start_pos += 1

if start_pos >= 7:

# If start_pos == 7 (Sunday) start new line

print()

start_pos = 0 # Reset counter

print()

def is_leap(year):

if year % 4 == 0:

if year % 100 == 0:

if year % 400 == 0:

return True

else:

return False

else:

return True

else:

return False

def is_days(year):

days_year = 0

for i in range(1753,year):

if is_leap(i):

days_year = days_year + 366

else:

days_year = days_year + 365

return days_year

def num_days_in_year(year):

return 365 + is_leap(year)

def is_decade(year):

'checks if year is a decade'

if year % 10 == 0:

return True

else:

return False

def main():

make_calendars = True

while make_calendars:

# create input loops for year and month to run calendar function

good_year = False

while good_year == False:

input_year = int(input('Enter the year (blank to exit): '))

# some code to ensure input is within datetime parameters

if input_year == '':

make_calendars = False

return None

else:

years = int(input_year)

if years < 1753:

print("Must enter an integer Higher than 1753")

else:

good_year = True

good_month = False

while good_month == False:

# a blank entry will print the entire year

input_month = input('Enter the month (blank to print entire year): ')

# some code to ensure input is within datetime parameters

if input_month == '':

for i in range(1,13):

calendar(i, years)

main()

else:

if input_month[0] == '0':

input_month = input_month[1:]

month = int(input_month)

if month < 1 or month > 12:

print("Must enter an integer between 1 and 12")

else:

good_month = True

if good_year == True and good_month == True:

calendar(month, years)

if is_decade(years):

print('This year is a decade')

else:

print('')

if is_leap(years):

print('This is a leap year')

else:

print('')

The_days = is_days(input_year )

calendar(input_year ,The_days)

if __name__ == '__main__':

main()

# for day in days:

# # Print day

# print('{0:<3}'.format(day), end='')

# start_pos += 1

# if start_pos >= 7:

# # If start_pos == 7 (Sunday) start new line

# print()

# start_pos = 0 # Reset counter

# print(' ')

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

Students also viewed these Databases questions