Program to convert an integer number to words

program to convert an integer number to words given a number. This is question recently asked me in the interview, So I wanted to share it. happy coding :).

PYTHON PROGRAM

Luminari

7/14/20241 min read

Question:

Program to convert an integer number to words

example : input 4721 , output : four thousand and seven hundred twenty one

Logic:

  1. We define dictionaries to map digits (0-9) to their corresponding words and place values (1, 10, 100, 1000) to their words.

  2. We extract each digit from the input number and find its word representation.

  3. We combine the digit word with the appropriate place word (e.g., “four” + “thousand”).

  4. Finally, we join all the words to form the complete representation.

For the number 4721, the output will be “four thousand seven hundred twenty one.”

Solution in python:

At the time of interview give 2 implementation.

We can improve implementation 2 to go with 100 and more, but this is the basic idea. But I feel implementation 1 is more sufficient.

Input : 72

output : seventy two

Preparing for interview?