def solution(num: int)-> list:
# your code here
t = True
b = ''
a = ''
list_num = []
dict_num = {'0':'zero','1':"one","2":"two",'3':'three','4':'four',
'5':'five','6':'six','7':'seven','8':'eight','9':'nine'}
if len(str(num)) == 1:
for i in str(num):
list_num.append(dict_num[i])
else:
for i in str(num):
b = b + dict_num[i]
list_num.append(b)
while t:
if len(list_num[-1]) <= 9:
list_num.append(dict_num[str(len(list_num[-1]))])
else:
for i in str(len(list_num[-1])):
a = a + dict_num[i]
list_num.append(a)
if len(list_num[-1]) == len(list_num[-2]):
t = False
break
print(list_num)
return list_num
assert solution(1) == ["one", "three", "five", "four"]
assert solution(37) == ["threeseven", "onezero", "seven", "five", "four"]
assert solution(999) == ["nineninenine", "onetwo", "six", "three", "five", "four"]
def solution(num: int)-> list:
l1=['zero','one','two','three','four','five','six','seven','eight','nine']
result = []
while num != 4:
translate = ""
for i in str(num):
translate += l1[int(i)]
result.append(translate)
num = len(translate)
result.append('four')
return result
class PaginationHelper:
# The constructor takes in an array of items and a integer indicating
# how many items fit within a single page
def __init__(self, collection, items_per_page):
self.collection = collection
self.items_per_page = items_per_page
# returns the number of items within the entire collection
def item_count(self):
return len(self.collection)
# returns the number of pages
# 返回页码数
def page_count(self):
# math.ceil()向上取整
integral_part = self.item_count()//self.items_per_page #取商
decimal_part = self.item_count()%self.items_per_page #取余/模
if decimal_part > 0:
return integral_part + 1
elif decimal_part== 0:
return integral_part
# returns the number of items on the current page. page_index is zero based
# this method should return -1 for page_index values that are out of range
# 根据页码索引返回当页数据量
def page_item_count(self, page_index):
# integral_part = self.item_count() // self.items_per_page
# decimal_part = self.item_count() % self.items_per_page
if 0<=page_index < (self.page_count()-1) :
return self.items_per_page
elif page_index == (self.page_count()-1):
return self.item_count()%self.items_per_page
else:
return -1
# determines what page an item is on. Zero based indexes.
# this method should return -1 for item_index values that are out of range
# 根据元素索引返回所在页码索引
def page_index(self, item_index):
page_index = item_index//self.items_per_page
print(page_index)
if 0<=page_index<=(self.page_count()-1) and item_index<=(self.item_count()-1):
return page_index
else:
return -1