# Non-functional: DATA_LIST = [] for i in the Range (1,901 ): data_list.append ( ' Bean Valley cloud -% S ' % i) the while True: # 1. You want to see the page number Page = int (the INPUT ( " Please enter the page number you want to view: " )) # 2. View how many data per_page_num = 10 # 3. define the start and end positions of each page start = (Page - 1) * per_page_num end = Page * per_page_num page_data_list = DATA_LIST [Start: End] for Item in page_data_list: print(item)
# Object Oriented: class Pagenation (Object): DEF the __init__ (Self, DATA_LIST, Page, per_data_num = 10 ): '' ' Initialization : param data_list: all listings data : param page: to be currently viewed list page : param per_data_num: Per the default page to be displayed several '' ' self.data_list = DATA_LIST self.page = page self.per_data_num = per_data_num @Property DEF start (Self): ' '' calculates the starting position of the lead cable : return: '' ' return ( self.page - 1) *self.per_data_num @Property DEF End (Self): '' ' calculates the end position of the lead cable : return: ' '' return self.page * self.per_data_num DEF Show (Self): '' ' slice data fetch, display the corresponding tab results : return: '' ' result = self.data_list [self.start: self.end] for Row in result: Print (Row) DATA_LIST = [] for I in Range (1,901 ): data_list.append ( ' beans Valley cloud -% s' % I) the while True: # 1. Enter the page number you want to view Page = int (the INPUT ( " Please enter the page number you want to see: " )) obj = Pagenation (DATA_LIST, Page) obj.show ()