code: def check_page_range(page_range, max_pages):
      
      pages = 0
      try:
          for r in page_range.split(","):  # check all ranges separated by commas
              if "-" in r:
                  rr = r.split("-")
                  if len(rr) != 2:  # make sure 2 values in range
                      return False
                  else:
                      rl = int(rr[0])
                      rh = int(rr[1])
                      # check in page range
                      if not 0 < rl < max_pages and not 0 < rh < max_pages:
                          return False
                      if rl > rh:  # check lower bound <= upper bound
                          return False
                      pages += rh - rl + 1
              else:
                  if not 0 < int(r) <= max_pages:  # check in page range
                      return False
                  pages += 1
      except ValueError:  # catch int parse fail
          return False
      return pages
docs: Returns the number of pages in the range, or False if it is an invalid range.