I made a calendar year program using python, but I'm having a problem the alignment of the 1st week. How do I fix this? pls. help XXXXXXXXXXMy code----------------- #init terminate = False...


I made a calendar year program using python, but I'm having a problem the alignment of the 1st week. How do I fix this? pls. help


------------------My code-----------------


#init


terminate = False
days_in_month = (31,28,31,30,31,30,31,31,30,31,30,31)


month_names = ('January', 'February', 'March', 'April', 'May', 'June','July', 'August', 'September', 'October', 'November', 'December')


calendar_year = []
month_separator = format(' ', '8')
blank_week = format(' ', '21')
blank_col = format(' ', '3')


# prompt for years until quit
while not terminate:


    #program greeting
    print('This program will display a calendar year for a given year')


    #get year
    year = int(input('Enter year (yyyy) (-1 to quit): '))
    while (year < 1800="" or="" year=""> 2099) and year != -1:
        year = int(input('INVALID - Enter year (1800-2099): '))


    if year == -1:
        terminate = True
    else:
        #get number of month per row
        months_per_row = int(input('Enter preferred number of months per row (2,3,4): '))
        while months_per_row not in (2,3,4):
            months_per_row = input('INVALID - Enter preferred number of months per row (2,3,4): ')


        if months_per_row == 2:
            first_month_rows = (0,2,4,6,8,10)
        elif months_per_row == 3:
            first_month_rows = (0,3,6,9)
        elif months_per_row == 4:
            first_month_rows = (0,4,8)

        #determine if leap year
        if (year % 4 == 0) and (not(year % 100 == 0) or (year % 400 == 0)):
            leap_year = True
        else:
            leap_year = False

        #determine day of the week
        century_digits = year // 100
        year_digits = year % 100
        value = year_digits + (year_digits // 4)


        if century_digits == 18:
            value = value + 2
        elif century_digits == 20:
            value = value + 6

        #leap year check
        if not leap_year:
            value = value + 1

        #determine the first day of the month for January 1
        first_day_of_current_month = (value + 1) % 7


        for month_num in range(12):
            month_name = month_names[month_num]


            #init for new month
            current_day = 1
            if first_day_of_current_month == 0:
                starting_col = 7
            else:
                starting_col = first_day_of_current_month

            current_col = 1
            calendar_week = ''
            calendar_month = []


            # add any needed leading space for the first week of the month
            while current_col <>
                calendar_week = calendar_week + blank_col
                current_col = current_col + 1


            #store month as separate weeks
            if (month_name == 'February') and leap_year:
                num_days_this_month = 29
            else:
                num_days_this_month = days_in_month[month_num]


            while current_day <=>


                #store day of month in field of length 3
                calendar_week = calendar_week + format(str(current_day),'>3')


                #check if at last column of displayed week
                if current_col == 7:
                    calendar_month = calendar_month + [calendar_week]
                    calendar_week = ''
                    current_col = 1
                else:
                    current_col = current_col + 1


                #increment current day
                current_day = current_day + 1


            # fill out final row of month with needed blanks
            calendar_week = calendar_week + blank_week[0:(7-current_col + 1) * 3]
            calendar_month = calendar_month + [calendar_week]

            #reset values for next month
            first_day_of_current_month = current_col
            calendar_year = calendar_year + [calendar_month]
            calendar_month = []

        #print calendar year
        print('\n', year, '\n')


        #number of months per row determined by months_per_row
        for month_num in first_month_rows:


            #displays month_per_row months in each row
            for i in range (month_num, month_num + months_per_row):
                print(' '+ format(month_names[i],'19'), month_separator, end='')

            #display each week of month on separate lines
            week=0
            lines_to_print = True


            while lines_to_print:

                #init
                lines_to_print = False

                #another week to display for first month in a row?
                for k in range(month_num, month_num + months_per_row):
                    if week <>

                        print(calendar_year[k][week], end='')
                        lines_to_print = True

                    else:
                        print(blank_week, end='')

                    print(month_separator, end='')

                #move to next screen line
                print()

                #increment week
                week = week + 1


This progran will display a calendar year for a given year<br>Enter year (yy) (-1 to quit): 2021<br>Enter preferred nunber of months per row (2,3,4): 3<br>2021<br>January<br>3456<br>February<br>1 2 3 45's<br>71 9 10 11 12 13<br>Parch<br>7 9 10 11 12 13<br>34567 9<br>10 11 12 13 14 15 16<br>14 15 16 17 18 19 20<br>14 15 16 17 18 19 20<br>17 18 19 20 21 22 23<br>21 22 23 24 25 26 27<br>21 22 23 24 25 26 27<br>24 25 26 27 28 2a<br>28<br>28 29 e 31<br>31<br>April<br>June<br>123<br>1 2<br>9 10<br>11 12 13 14 15 16 17<br>6 789 10 11 12<br>23 45678<br>9 10 11 12 13 14 15<br>4567<br>13 14 15 14 17 8 19<br>18 19 20 21 22 23 24<br>16 17 18 19 20 21 22<br>20 21 22 23 24 25 24<br>25 26 27 28 29<br>23 24 25 26 27 28 29<br>27 28 29<br>July<br>1 23<br>12 3<br>August<br>123 4<br>Septenber<br>4567<br>

Extracted text: This progran will display a calendar year for a given year Enter year (yy) (-1 to quit): 2021 Enter preferred nunber of months per row (2,3,4): 3 2021 January 3456 February 1 2 3 45's 71 9 10 11 12 13 Parch 7 9 10 11 12 13 34567 9 10 11 12 13 14 15 16 14 15 16 17 18 19 20 14 15 16 17 18 19 20 17 18 19 20 21 22 23 21 22 23 24 25 26 27 21 22 23 24 25 26 27 24 25 26 27 28 2a 28 28 29 e 31 31 April June 123 1 2 9 10 11 12 13 14 15 16 17 6 789 10 11 12 23 45678 9 10 11 12 13 14 15 4567 13 14 15 14 17 8 19 18 19 20 21 22 23 24 16 17 18 19 20 21 22 20 21 22 23 24 25 24 25 26 27 28 29 23 24 25 26 27 28 29 27 28 29 July 1 23 12 3 August 123 4 Septenber 4567
Jun 06, 2022
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here