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

What does an unprocessed RAW file look like?

Resorting data from a multidimensional list

Are all power cords made equal?

How to Build a List from Separate Lists

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

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

What happens if both players misunderstand the game state until it's too late?

Are one-line email responses considered disrespectful?

Is there a name for this series?

Proving the Borel-Cantelli Lemma

Identify non-coding regions from a genome annotation

Crack the bank account's password!

What really causes series inductance of capacitors?

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

Does the double-bladed scimitar's special attack let you use your ability modifier for the damage of the attack?

Will the duration of traveling to Ceres using the same tech developed for going to Mars be proportional to the distance to go to Mars or not?

Is the tritone (A4 / d5) still banned in Roman Catholic music?

Including proofs of known theorems in master's thesis

How to transport 10,000 terrestrial trolls across ocean fast?

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

Do the speed limit reductions due to pollution also apply to electric cars in France?

Is Screenshot Time-tracking Common?

Why don't you get burned by the wood benches in a sauna?

Can I legally make a website about boycotting a certain company?



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













7












$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
















7












$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














7












7








7





$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 30 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

363




363




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


















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
    58 mins ago



















2












$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$













    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









    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
      58 mins 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
      58 mins 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 55 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
      58 mins 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
      58 mins 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
    58 mins 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
    58 mins ago













    2












    $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$

      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












        2








        2





        $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 25 mins ago









        422_unprocessable_entity422_unprocessable_entity

        1,94631750




        1,94631750






















            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

            Szabolcs (Ungheria) Altri progetti | Menu di navigazione48°10′14.56″N 21°29′33.14″E /...

            Discografia di Klaus Schulze Indice Album in studio | Album dal vivo | Singoli | Antologie | Colonne...

            How to make inet_server_addr() return localhost in spite of ::1/128RETURN NEXT in Postgres FunctionConnect to...