Drawing Book

  • + 0 comments
    def pageCount(n, p):
        # Write your code here
        if (n == 1 or n==p):
            return 0
        if (n % 2 > 0 and p == n-1):
            return 0
        midpage1, midpage2 = int(n/2), int(n/2) + 1
        page_counter = 0
        if (p <= midpage1):
            start = 1
            while (start < p):
                start += 2
                page_counter += 1
        elif (p >= midpage2):
            start = n-1
            if (start==p):
                return 1
            while (start > p):
                start -= 2
                page_counter += 1
        return page_counter