How to convert an integer number to words in python?

前端 未结 6 674
走了就别回头了
走了就别回头了 2021-01-21 05:09

Write a function that takes an integer as input argument and returns the integer using words. For example if the input is 4721 then the function should retur

6条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-01-21 05:46

    There is a way that is simpler than the rest:

    def number_to_words(number)
        words = ["zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten"]
        return " ".join(words[int(i)] for i in str(number))
    

提交回复
热议问题