コード例 #1
0
"""  I/P -> Year, ensure it is a 4 digit number.
     Logic -> Determine if it is a Leap Year.
     O/P -> Print the year is a Leap Year or not."""

from UtilityMethods import Utility
try:
    year = int(input("enter the year \n"))
    Utility.leap_year(year)
except Exception as e:
    print(e)
    print("enter the integer")
コード例 #2
0
    def calender_queue(self, month, year):
        """
            This method is used to print calender of given month and year.
            In this method calender is created using queue
            month   : month given ser
            year    : year given by year

        """
        day = ['S', ' M', ' T', ' W', ' Th', 'F', ' S']

        days = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]

        values = 1

        d = 1

        m = month

        y = year

        y0 = y - (14 - m) // 12

        x = y0 + y0 // 4 - y0 // 100 + y0 // 400

        m0 = m + 12 * ((14 - m) // 12) - 2

        d0 = (d + x + 31 * m0 // 12) % 7

        if Utility.leap_year(year):  # check leap year

            days[1] = 29

        row = 6

        column = 7

        print('Your Calender is\n')

        for i in range(0, 6 + 1):

            print(day[i], end=' ')  # print day's for calender

        print()

        for i in range(row):

            for j in range(column):

                if values <= days[m - 1]:  # while d0 is less than j

                    if i == 0 and j < d0:  # it will print blank space

                        queue1.enqueue(
                            ' ')  # used enqueue() method of queue class

                        continue  # to add space

                    queue1.enqueue(values)  # add element in queue

                    values += 1

        for i in range(row):

            for j in range(column):

                if queue1.size() > 0:

                    x = queue1.dequeue(
                    )  # remove element from queue and store it in x variable

                    x1 = str(x).ljust(
                        2)  # using l just() method print formatted calender

                    print(x1, end=" ")

            print()
コード例 #3
0
    def calender_stack(self, month, year):
        """
            This method is used to print calender of given month and year.
            In this method calender is created using stack
            month :  month given by user
            year  :  year given by user
        """
        day = ['S', ' M', ' T', ' W', ' Th', 'F', ' S']

        days = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]

        values = 1

        d = 1

        m = month

        y = year

        y0 = y - (14 - m) // 12

        x = y0 + y0 // 4 - y0 // 100 + y0 // 400

        m0 = m + 12 * ((14 - m) // 12) - 2

        d0 = (d + x + 31 * m0 // 12) % 7

        if Utility.leap_year(year):  # check leap year

            days[1] = 29

        row = 6

        column = 7

        print('Your Calender is Ready\n')

        for i in range(0, 6 + 1):

            print(day[i], end=' ')  # print day's for calender

        print()

        for i in range(row):

            for j in range(column):

                if values <= days[m - 1]:  # while d0 is less than j

                    if i == 0 and j < d0:  # it will print blank space

                        stack.push(' ')  # use push() to add blanks

                        continue

                    stack.push(values)  # add days using push() method

                    values += 1

        for i in range(stack.size()):

            stack_element = stack.pop(
            )  # pop element from stack and store in local variable

            stack1.push(
                stack_element)  # again push element into stack for reverse

        for i in range(row):

            for j in range(column):

                if stack1.size() > 0:

                    x = stack1.pop(
                    )  # access element one by one using pop() method

                    x1 = str(x).ljust(
                        2)  # l just() method to print in calender structure

                    print(x1, end=" ")

            print()
コード例 #4
0
    def calender(self, month, year):
        """
            This method is used to print Calender of given month and year.
            month  :  month given by user
            year   :  year given by user
        """

        day = ['S', ' M', ' T', ' W', ' Th', 'F', ' S']

        days = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]

        values = 1

        d = 1

        m = month

        y = year

        y0 = y - (14 - m) // 12

        x = y0 + y0 // 4 - y0 // 100 + y0 // 400

        m0 = m + 12 * ((14 - m) // 12) - 2

        d0 = (d + x + 31 * m0 // 12) % 7

        print(d0)

        if Utility.leap_year(year):  # check leap year

            days[1] = 29

        row = 6

        column = 7

        two_d_array = [[0 for j in range(column)]
                       for i in range(row)]  # create empty 2d array

        print('Your Calender is\n')

        for i in range(0, 6 + 1):

            print(day[i], end=' ')  # print day's for calender

        print()

        for i in range(row):

            for j in range(column):

                if values <= days[m - 1]:

                    if i == 0 and j < d0:  # while d0 is less than j

                        two_d_array[i][j] = ' '  # it will print blank space

                        continue

                    two_d_array[i][j] = values  # add days into calender

                    values += 1  # increment counter

        for i in range(row):

            for j in range(column):

                if two_d_array[i][j] != 0:

                    x = two_d_array[i][j]  # l just() method returns the string

                    x1 = str(x).ljust(
                        2)  # left justified in a string of length width.

                    print(x1, end=" ")

            print()