Converting numbers to words - PythonConverting a large number into something like: 4 NovemnongentNumbers to...

Why write a book when there's a movie in my head?

How to store all ctor parameters in fields

When distributing a Linux kernel driver as source code, what's the difference between Proprietary and GPL license?

Is it possible to narrate a novel in a faux-historical style without alienating the reader?

Is Screenshot Time-tracking Common?

Is there any danger of my neighbor having my wife's signature?

What is an efficient way to digitize a family photo collection?

Protagonist constantly has to have long words explained to her. Will this get tedious?

Buying a "Used" Router

Missing a connection and don't have money to book next flight

How do I add a strong "onion flavor" to the biryani (in restaurant style)?

Trying to make a 3dplot

What does an unprocessed RAW file look like?

How do I make my single-minded character more interested in the main story?

Why can all solutions to the simple harmonic motion equation be written in terms of sines and cosines?

Partial derivative with respect to three variables

Is it possible to detect 100% of SQLi with a simple regex?

Identical projects by students at two different colleges: still plagiarism?

Multiple null checks in Java 8

Why is it that Bernie Sanders always called a "socialist"?

How do I narratively explain how in-game circumstances do not mechanically allow a PC to instantly kill an NPC?

What is the reward?

Can I do anything else with aspersions other than cast them?

How can changes in personality/values of a person who turned into a vampire be explained?



Converting numbers to words - Python


Converting a large number into something like: 4 NovemnongentNumbers to words converterConvert a number to textPutting numbers into wordsConverting numbers to English wordsTime Card Web Application OfflineConverting number to wordsNumber to words in Python 3Converting numbers to words in HaskellConverting English words to numbers in HaskellPython Converting numbers to words, using Recursive













8












$begingroup$


I'm new to programming. I tried to find a way to convert numbers into letters with Python. I would like to receive some advice to improve myself. This program works for numbers between 1 and 106 and I would like to know how the logic of the program can be improved.



def changeNumberIntoLetter(value):
number=numToLetter(value)
return number

def numToLetter(value): #The function converts the numbers into letters.
if value==1: return 'one'
elif value==2: return 'two'
elif value==3: return 'three'
elif value==4: return 'four'
elif value==5: return 'five'
elif value==6: return 'six'
elif value==7: return 'seven'
elif value==8: return 'eight'
elif value==9: return 'nine'
elif value==10: return 'ten'
elif value==11: return 'eleven'
elif value==12: return 'twelve'
elif value==13: return 'thirteen'
elif 13<value<=19: return composeTeen(value)
elif value>19:
if value==20: return 'twenty'
elif value==30: return 'thirty'
elif value==50: return 'fifty'
elif value==10**2: return 'one hundred'
elif value==10**3: return 'one thousand'
elif value==10**5: return 'one hundred thousand'
elif value==10**6: return 'one milion'
elif value>=20: return composeNumbers(value)
else: exit('Out of range')
else: return ''

def composeNumbers(value): #The function build every number biger than 40
if 40<=value<10**2:
value1=int(str(value)[0])
value2= int(str(value)[1])
if value1==2:
value1= 'twen'
return value1 + 'ty' + '-' + numToLetter(value2)
if value1==3:
value1='thir'
return value1 + 'ty' + '-' + numToLetter(value2)
if value1==8:
value1='eigh'
return value1 + 'ty' + '-' + numToLetter(value2)
elif value1==5:
value1='fif'
return value1 + 'ty' + '-' + numToLetter(value2)
return numToLetter(value1) + 'ty' + '-' + numToLetter(value2)
elif 10**2<=value<10**3:
value1=int(str(value)[0])
value2= int(str(value)[1:])
return numToLetter(value1) + ' ' + 'hundred' + ' ' + numToLetter(value2)
elif 10**3<=value<10**4:
value1=int(str(value)[0])
value2=int(str(value)[1:])
elif 10**4<=value<10**5:
value1=int(str(value)[0:2])
value2=int(str(value)[2:])
elif 10**5<=value<10**6:
value1=int(str(value)[0:3])
value2=int(str(value)[3:])
return numToLetter(value1) + ' ' + 'thousand' + ' ' + numToLetter(value2)



def composeTeen(value): #The function takes the unit and then converts it into letter to build the word.
value= int(str(value)[-1]) #It turns elem in string to take the last position and it converts it again in integer to change it in letters. Then it composes the word adding 'teen' at the end.
value= numToLetter(value)
if value=='five': value= 'fif'
value= value + 'teen'
return value









share|improve this question









New contributor




Roberta Belladonna is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.







$endgroup$












  • $begingroup$
    Something which could help you make this code effective is if you have a look at this code, codereview.stackexchange.com/questions/182833/…, it is not an answer because it doesn't do it just words but it uses techniques which could be good for what you are trying to do
    $endgroup$
    – 13ros27
    1 hour ago
















8












$begingroup$


I'm new to programming. I tried to find a way to convert numbers into letters with Python. I would like to receive some advice to improve myself. This program works for numbers between 1 and 106 and I would like to know how the logic of the program can be improved.



def changeNumberIntoLetter(value):
number=numToLetter(value)
return number

def numToLetter(value): #The function converts the numbers into letters.
if value==1: return 'one'
elif value==2: return 'two'
elif value==3: return 'three'
elif value==4: return 'four'
elif value==5: return 'five'
elif value==6: return 'six'
elif value==7: return 'seven'
elif value==8: return 'eight'
elif value==9: return 'nine'
elif value==10: return 'ten'
elif value==11: return 'eleven'
elif value==12: return 'twelve'
elif value==13: return 'thirteen'
elif 13<value<=19: return composeTeen(value)
elif value>19:
if value==20: return 'twenty'
elif value==30: return 'thirty'
elif value==50: return 'fifty'
elif value==10**2: return 'one hundred'
elif value==10**3: return 'one thousand'
elif value==10**5: return 'one hundred thousand'
elif value==10**6: return 'one milion'
elif value>=20: return composeNumbers(value)
else: exit('Out of range')
else: return ''

def composeNumbers(value): #The function build every number biger than 40
if 40<=value<10**2:
value1=int(str(value)[0])
value2= int(str(value)[1])
if value1==2:
value1= 'twen'
return value1 + 'ty' + '-' + numToLetter(value2)
if value1==3:
value1='thir'
return value1 + 'ty' + '-' + numToLetter(value2)
if value1==8:
value1='eigh'
return value1 + 'ty' + '-' + numToLetter(value2)
elif value1==5:
value1='fif'
return value1 + 'ty' + '-' + numToLetter(value2)
return numToLetter(value1) + 'ty' + '-' + numToLetter(value2)
elif 10**2<=value<10**3:
value1=int(str(value)[0])
value2= int(str(value)[1:])
return numToLetter(value1) + ' ' + 'hundred' + ' ' + numToLetter(value2)
elif 10**3<=value<10**4:
value1=int(str(value)[0])
value2=int(str(value)[1:])
elif 10**4<=value<10**5:
value1=int(str(value)[0:2])
value2=int(str(value)[2:])
elif 10**5<=value<10**6:
value1=int(str(value)[0:3])
value2=int(str(value)[3:])
return numToLetter(value1) + ' ' + 'thousand' + ' ' + numToLetter(value2)



def composeTeen(value): #The function takes the unit and then converts it into letter to build the word.
value= int(str(value)[-1]) #It turns elem in string to take the last position and it converts it again in integer to change it in letters. Then it composes the word adding 'teen' at the end.
value= numToLetter(value)
if value=='five': value= 'fif'
value= value + 'teen'
return value









share|improve this question









New contributor




Roberta Belladonna is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.







$endgroup$












  • $begingroup$
    Something which could help you make this code effective is if you have a look at this code, codereview.stackexchange.com/questions/182833/…, it is not an answer because it doesn't do it just words but it uses techniques which could be good for what you are trying to do
    $endgroup$
    – 13ros27
    1 hour ago














8












8








8





$begingroup$


I'm new to programming. I tried to find a way to convert numbers into letters with Python. I would like to receive some advice to improve myself. This program works for numbers between 1 and 106 and I would like to know how the logic of the program can be improved.



def changeNumberIntoLetter(value):
number=numToLetter(value)
return number

def numToLetter(value): #The function converts the numbers into letters.
if value==1: return 'one'
elif value==2: return 'two'
elif value==3: return 'three'
elif value==4: return 'four'
elif value==5: return 'five'
elif value==6: return 'six'
elif value==7: return 'seven'
elif value==8: return 'eight'
elif value==9: return 'nine'
elif value==10: return 'ten'
elif value==11: return 'eleven'
elif value==12: return 'twelve'
elif value==13: return 'thirteen'
elif 13<value<=19: return composeTeen(value)
elif value>19:
if value==20: return 'twenty'
elif value==30: return 'thirty'
elif value==50: return 'fifty'
elif value==10**2: return 'one hundred'
elif value==10**3: return 'one thousand'
elif value==10**5: return 'one hundred thousand'
elif value==10**6: return 'one milion'
elif value>=20: return composeNumbers(value)
else: exit('Out of range')
else: return ''

def composeNumbers(value): #The function build every number biger than 40
if 40<=value<10**2:
value1=int(str(value)[0])
value2= int(str(value)[1])
if value1==2:
value1= 'twen'
return value1 + 'ty' + '-' + numToLetter(value2)
if value1==3:
value1='thir'
return value1 + 'ty' + '-' + numToLetter(value2)
if value1==8:
value1='eigh'
return value1 + 'ty' + '-' + numToLetter(value2)
elif value1==5:
value1='fif'
return value1 + 'ty' + '-' + numToLetter(value2)
return numToLetter(value1) + 'ty' + '-' + numToLetter(value2)
elif 10**2<=value<10**3:
value1=int(str(value)[0])
value2= int(str(value)[1:])
return numToLetter(value1) + ' ' + 'hundred' + ' ' + numToLetter(value2)
elif 10**3<=value<10**4:
value1=int(str(value)[0])
value2=int(str(value)[1:])
elif 10**4<=value<10**5:
value1=int(str(value)[0:2])
value2=int(str(value)[2:])
elif 10**5<=value<10**6:
value1=int(str(value)[0:3])
value2=int(str(value)[3:])
return numToLetter(value1) + ' ' + 'thousand' + ' ' + numToLetter(value2)



def composeTeen(value): #The function takes the unit and then converts it into letter to build the word.
value= int(str(value)[-1]) #It turns elem in string to take the last position and it converts it again in integer to change it in letters. Then it composes the word adding 'teen' at the end.
value= numToLetter(value)
if value=='five': value= 'fif'
value= value + 'teen'
return value









share|improve this question









New contributor




Roberta Belladonna is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.







$endgroup$




I'm new to programming. I tried to find a way to convert numbers into letters with Python. I would like to receive some advice to improve myself. This program works for numbers between 1 and 106 and I would like to know how the logic of the program can be improved.



def changeNumberIntoLetter(value):
number=numToLetter(value)
return number

def numToLetter(value): #The function converts the numbers into letters.
if value==1: return 'one'
elif value==2: return 'two'
elif value==3: return 'three'
elif value==4: return 'four'
elif value==5: return 'five'
elif value==6: return 'six'
elif value==7: return 'seven'
elif value==8: return 'eight'
elif value==9: return 'nine'
elif value==10: return 'ten'
elif value==11: return 'eleven'
elif value==12: return 'twelve'
elif value==13: return 'thirteen'
elif 13<value<=19: return composeTeen(value)
elif value>19:
if value==20: return 'twenty'
elif value==30: return 'thirty'
elif value==50: return 'fifty'
elif value==10**2: return 'one hundred'
elif value==10**3: return 'one thousand'
elif value==10**5: return 'one hundred thousand'
elif value==10**6: return 'one milion'
elif value>=20: return composeNumbers(value)
else: exit('Out of range')
else: return ''

def composeNumbers(value): #The function build every number biger than 40
if 40<=value<10**2:
value1=int(str(value)[0])
value2= int(str(value)[1])
if value1==2:
value1= 'twen'
return value1 + 'ty' + '-' + numToLetter(value2)
if value1==3:
value1='thir'
return value1 + 'ty' + '-' + numToLetter(value2)
if value1==8:
value1='eigh'
return value1 + 'ty' + '-' + numToLetter(value2)
elif value1==5:
value1='fif'
return value1 + 'ty' + '-' + numToLetter(value2)
return numToLetter(value1) + 'ty' + '-' + numToLetter(value2)
elif 10**2<=value<10**3:
value1=int(str(value)[0])
value2= int(str(value)[1:])
return numToLetter(value1) + ' ' + 'hundred' + ' ' + numToLetter(value2)
elif 10**3<=value<10**4:
value1=int(str(value)[0])
value2=int(str(value)[1:])
elif 10**4<=value<10**5:
value1=int(str(value)[0:2])
value2=int(str(value)[2:])
elif 10**5<=value<10**6:
value1=int(str(value)[0:3])
value2=int(str(value)[3:])
return numToLetter(value1) + ' ' + 'thousand' + ' ' + numToLetter(value2)



def composeTeen(value): #The function takes the unit and then converts it into letter to build the word.
value= int(str(value)[-1]) #It turns elem in string to take the last position and it converts it again in integer to change it in letters. Then it composes the word adding 'teen' at the end.
value= numToLetter(value)
if value=='five': value= 'fif'
value= value + 'teen'
return value






python beginner numbers-to-words






share|improve this question









New contributor




Roberta Belladonna is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question









New contributor




Roberta Belladonna is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question








edited 35 mins ago







Roberta Belladonna













New contributor




Roberta Belladonna is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked 1 hour ago









Roberta BelladonnaRoberta Belladonna

413




413




New contributor




Roberta Belladonna is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





Roberta Belladonna is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






Roberta Belladonna is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.












  • $begingroup$
    Something which could help you make this code effective is if you have a look at this code, codereview.stackexchange.com/questions/182833/…, it is not an answer because it doesn't do it just words but it uses techniques which could be good for what you are trying to do
    $endgroup$
    – 13ros27
    1 hour ago


















  • $begingroup$
    Something which could help you make this code effective is if you have a look at this code, codereview.stackexchange.com/questions/182833/…, it is not an answer because it doesn't do it just words but it uses techniques which could be good for what you are trying to do
    $endgroup$
    – 13ros27
    1 hour ago
















$begingroup$
Something which could help you make this code effective is if you have a look at this code, codereview.stackexchange.com/questions/182833/…, it is not an answer because it doesn't do it just words but it uses techniques which could be good for what you are trying to do
$endgroup$
– 13ros27
1 hour ago




$begingroup$
Something which could help you make this code effective is if you have a look at this code, codereview.stackexchange.com/questions/182833/…, it is not an answer because it doesn't do it just words but it uses techniques which could be good for what you are trying to do
$endgroup$
– 13ros27
1 hour ago










2 Answers
2






active

oldest

votes


















3












$begingroup$

This is good work! Well done as a beginner programmer.




def changeNumberIntoLetter(value):
number=numToLetter(value)
return number



This function doesn't really do anything useful to be honest. Can't you directly use numToLetter.




if value==1: return 'one'
elif value==2: return 'two'
elif value==3: return 'three'
elif value==4: return 'four'
elif value==5: return 'five'
elif value==6: return 'six'



Instead of creating lot of if statements. Try using a dictionary like this:



NUM_TO_WORD_MAPPING = {1: "one", 2: "two"}


and you can refer the string to number using



if value in NUM_TO_WORD_MAPPING:
return NUM_TO_WORD_MAPPING[value]
else:
# ... special cases.



int(str(value)[-1])



use value % 10 to extract numbers easily. This is modulo operator and returns remainder after division.






share|improve this answer









$endgroup$





















    2












    $begingroup$

    I did this by inflect pypi library:



    import inflect

    ig = inflect.engine()
    print(ig.number_to_words(85))


    Out:



    eighty-five




    [NOTE]:



    Install inflect library by pip:



    $ pip install inflect




    Furthermore, I found this method too:



    >>> import num2word
    >>> num2word.to_card(15)
    'fifteen'
    >>> num2word.to_card(55)
    'fifty-five'
    >>> num2word.to_card(1555)
    'one thousand, five hundred and fifty-five'




    [NOTE]:



    These are the Github link of mentioned libraries if you want to know how they implemented:




    • inflect Github

    • num2words Github






    share|improve this answer










    New contributor




    Benyamin Jafari is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.






    $endgroup$









    • 2




      $begingroup$
      Offloading to others is good, Pythonic even. But this doesn't really help the person improve their own programing abilities.
      $endgroup$
      – Peilonrayz
      1 hour ago










    • $begingroup$
      I got it, so if he wants to know how these libraries implemented, I'll update my answer with the Github links of these libraries.
      $endgroup$
      – Benyamin Jafari
      1 hour ago











    Your Answer





    StackExchange.ifUsing("editor", function () {
    return StackExchange.using("mathjaxEditing", function () {
    StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix) {
    StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["\$", "\$"]]);
    });
    });
    }, "mathjax-editing");

    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "196"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: false,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });






    Roberta Belladonna is a new contributor. Be nice, and check out our Code of Conduct.










    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f214053%2fconverting-numbers-to-words-python%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    3












    $begingroup$

    This is good work! Well done as a beginner programmer.




    def changeNumberIntoLetter(value):
    number=numToLetter(value)
    return number



    This function doesn't really do anything useful to be honest. Can't you directly use numToLetter.




    if value==1: return 'one'
    elif value==2: return 'two'
    elif value==3: return 'three'
    elif value==4: return 'four'
    elif value==5: return 'five'
    elif value==6: return 'six'



    Instead of creating lot of if statements. Try using a dictionary like this:



    NUM_TO_WORD_MAPPING = {1: "one", 2: "two"}


    and you can refer the string to number using



    if value in NUM_TO_WORD_MAPPING:
    return NUM_TO_WORD_MAPPING[value]
    else:
    # ... special cases.



    int(str(value)[-1])



    use value % 10 to extract numbers easily. This is modulo operator and returns remainder after division.






    share|improve this answer









    $endgroup$


















      3












      $begingroup$

      This is good work! Well done as a beginner programmer.




      def changeNumberIntoLetter(value):
      number=numToLetter(value)
      return number



      This function doesn't really do anything useful to be honest. Can't you directly use numToLetter.




      if value==1: return 'one'
      elif value==2: return 'two'
      elif value==3: return 'three'
      elif value==4: return 'four'
      elif value==5: return 'five'
      elif value==6: return 'six'



      Instead of creating lot of if statements. Try using a dictionary like this:



      NUM_TO_WORD_MAPPING = {1: "one", 2: "two"}


      and you can refer the string to number using



      if value in NUM_TO_WORD_MAPPING:
      return NUM_TO_WORD_MAPPING[value]
      else:
      # ... special cases.



      int(str(value)[-1])



      use value % 10 to extract numbers easily. This is modulo operator and returns remainder after division.






      share|improve this answer









      $endgroup$
















        3












        3








        3





        $begingroup$

        This is good work! Well done as a beginner programmer.




        def changeNumberIntoLetter(value):
        number=numToLetter(value)
        return number



        This function doesn't really do anything useful to be honest. Can't you directly use numToLetter.




        if value==1: return 'one'
        elif value==2: return 'two'
        elif value==3: return 'three'
        elif value==4: return 'four'
        elif value==5: return 'five'
        elif value==6: return 'six'



        Instead of creating lot of if statements. Try using a dictionary like this:



        NUM_TO_WORD_MAPPING = {1: "one", 2: "two"}


        and you can refer the string to number using



        if value in NUM_TO_WORD_MAPPING:
        return NUM_TO_WORD_MAPPING[value]
        else:
        # ... special cases.



        int(str(value)[-1])



        use value % 10 to extract numbers easily. This is modulo operator and returns remainder after division.






        share|improve this answer









        $endgroup$



        This is good work! Well done as a beginner programmer.




        def changeNumberIntoLetter(value):
        number=numToLetter(value)
        return number



        This function doesn't really do anything useful to be honest. Can't you directly use numToLetter.




        if value==1: return 'one'
        elif value==2: return 'two'
        elif value==3: return 'three'
        elif value==4: return 'four'
        elif value==5: return 'five'
        elif value==6: return 'six'



        Instead of creating lot of if statements. Try using a dictionary like this:



        NUM_TO_WORD_MAPPING = {1: "one", 2: "two"}


        and you can refer the string to number using



        if value in NUM_TO_WORD_MAPPING:
        return NUM_TO_WORD_MAPPING[value]
        else:
        # ... special cases.



        int(str(value)[-1])



        use value % 10 to extract numbers easily. This is modulo operator and returns remainder after division.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered 30 mins ago









        422_unprocessable_entity422_unprocessable_entity

        1,95631750




        1,95631750

























            2












            $begingroup$

            I did this by inflect pypi library:



            import inflect

            ig = inflect.engine()
            print(ig.number_to_words(85))


            Out:



            eighty-five




            [NOTE]:



            Install inflect library by pip:



            $ pip install inflect




            Furthermore, I found this method too:



            >>> import num2word
            >>> num2word.to_card(15)
            'fifteen'
            >>> num2word.to_card(55)
            'fifty-five'
            >>> num2word.to_card(1555)
            'one thousand, five hundred and fifty-five'




            [NOTE]:



            These are the Github link of mentioned libraries if you want to know how they implemented:




            • inflect Github

            • num2words Github






            share|improve this answer










            New contributor




            Benyamin Jafari is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
            Check out our Code of Conduct.






            $endgroup$









            • 2




              $begingroup$
              Offloading to others is good, Pythonic even. But this doesn't really help the person improve their own programing abilities.
              $endgroup$
              – Peilonrayz
              1 hour ago










            • $begingroup$
              I got it, so if he wants to know how these libraries implemented, I'll update my answer with the Github links of these libraries.
              $endgroup$
              – Benyamin Jafari
              1 hour ago
















            2












            $begingroup$

            I did this by inflect pypi library:



            import inflect

            ig = inflect.engine()
            print(ig.number_to_words(85))


            Out:



            eighty-five




            [NOTE]:



            Install inflect library by pip:



            $ pip install inflect




            Furthermore, I found this method too:



            >>> import num2word
            >>> num2word.to_card(15)
            'fifteen'
            >>> num2word.to_card(55)
            'fifty-five'
            >>> num2word.to_card(1555)
            'one thousand, five hundred and fifty-five'




            [NOTE]:



            These are the Github link of mentioned libraries if you want to know how they implemented:




            • inflect Github

            • num2words Github






            share|improve this answer










            New contributor




            Benyamin Jafari is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
            Check out our Code of Conduct.






            $endgroup$









            • 2




              $begingroup$
              Offloading to others is good, Pythonic even. But this doesn't really help the person improve their own programing abilities.
              $endgroup$
              – Peilonrayz
              1 hour ago










            • $begingroup$
              I got it, so if he wants to know how these libraries implemented, I'll update my answer with the Github links of these libraries.
              $endgroup$
              – Benyamin Jafari
              1 hour ago














            2












            2








            2





            $begingroup$

            I did this by inflect pypi library:



            import inflect

            ig = inflect.engine()
            print(ig.number_to_words(85))


            Out:



            eighty-five




            [NOTE]:



            Install inflect library by pip:



            $ pip install inflect




            Furthermore, I found this method too:



            >>> import num2word
            >>> num2word.to_card(15)
            'fifteen'
            >>> num2word.to_card(55)
            'fifty-five'
            >>> num2word.to_card(1555)
            'one thousand, five hundred and fifty-five'




            [NOTE]:



            These are the Github link of mentioned libraries if you want to know how they implemented:




            • inflect Github

            • num2words Github






            share|improve this answer










            New contributor




            Benyamin Jafari is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
            Check out our Code of Conduct.






            $endgroup$



            I did this by inflect pypi library:



            import inflect

            ig = inflect.engine()
            print(ig.number_to_words(85))


            Out:



            eighty-five




            [NOTE]:



            Install inflect library by pip:



            $ pip install inflect




            Furthermore, I found this method too:



            >>> import num2word
            >>> num2word.to_card(15)
            'fifteen'
            >>> num2word.to_card(55)
            'fifty-five'
            >>> num2word.to_card(1555)
            'one thousand, five hundred and fifty-five'




            [NOTE]:



            These are the Github link of mentioned libraries if you want to know how they implemented:




            • inflect Github

            • num2words Github







            share|improve this answer










            New contributor




            Benyamin Jafari is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
            Check out our Code of Conduct.









            share|improve this answer



            share|improve this answer








            edited 59 mins ago





















            New contributor




            Benyamin Jafari is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
            Check out our Code of Conduct.









            answered 1 hour ago









            Benyamin JafariBenyamin Jafari

            1214




            1214




            New contributor




            Benyamin Jafari is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
            Check out our Code of Conduct.





            New contributor





            Benyamin Jafari is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
            Check out our Code of Conduct.






            Benyamin Jafari is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
            Check out our Code of Conduct.








            • 2




              $begingroup$
              Offloading to others is good, Pythonic even. But this doesn't really help the person improve their own programing abilities.
              $endgroup$
              – Peilonrayz
              1 hour ago










            • $begingroup$
              I got it, so if he wants to know how these libraries implemented, I'll update my answer with the Github links of these libraries.
              $endgroup$
              – Benyamin Jafari
              1 hour ago














            • 2




              $begingroup$
              Offloading to others is good, Pythonic even. But this doesn't really help the person improve their own programing abilities.
              $endgroup$
              – Peilonrayz
              1 hour ago










            • $begingroup$
              I got it, so if he wants to know how these libraries implemented, I'll update my answer with the Github links of these libraries.
              $endgroup$
              – Benyamin Jafari
              1 hour ago








            2




            2




            $begingroup$
            Offloading to others is good, Pythonic even. But this doesn't really help the person improve their own programing abilities.
            $endgroup$
            – Peilonrayz
            1 hour ago




            $begingroup$
            Offloading to others is good, Pythonic even. But this doesn't really help the person improve their own programing abilities.
            $endgroup$
            – Peilonrayz
            1 hour ago












            $begingroup$
            I got it, so if he wants to know how these libraries implemented, I'll update my answer with the Github links of these libraries.
            $endgroup$
            – Benyamin Jafari
            1 hour ago




            $begingroup$
            I got it, so if he wants to know how these libraries implemented, I'll update my answer with the Github links of these libraries.
            $endgroup$
            – Benyamin Jafari
            1 hour ago










            Roberta Belladonna is a new contributor. Be nice, and check out our Code of Conduct.










            draft saved

            draft discarded


















            Roberta Belladonna is a new contributor. Be nice, and check out our Code of Conduct.













            Roberta Belladonna is a new contributor. Be nice, and check out our Code of Conduct.












            Roberta Belladonna is a new contributor. Be nice, and check out our Code of Conduct.
















            Thanks for contributing an answer to Code Review Stack Exchange!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            Use MathJax to format equations. MathJax reference.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f214053%2fconverting-numbers-to-words-python%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Щит и меч (фильм) Содержание Названия серий | Сюжет |...

            is 'sed' thread safeWhat should someone know about using Python scripts in the shell?Nexenta bash script uses...

            Meter-Bus Содержание Параметры шины | Стандартизация |...