排序題

CodeWars上的排序題

Your task is to make a function that can take any non-negative integer as a argument and return it with its digits in descending order.
Essentially, rearrange the digits to create the highest possible number.
Examples:
Input: 21445 Output: 54421
Input: 145263 Output: 654321

Input: 1254859723 Output: 9875543221

def descend_range(number):
    num = []
    if (number<0):
        print("Please enter a non-negative number")
    else:
        for i in range(len(str(number))):
            num.append(str(number)[i])
        num = ''.join(sorted(num, reverse=True))
        print(num)


num = 18754984586
descend_range(num)

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章