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:
We define dictionaries to map digits (0-9) to their corresponding words and place values (1, 10, 100, 1000) to their words.
We extract each digit from the input number and find its word representation.
We combine the digit word with the appropriate place word (e.g., “four” + “thousand”).
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?
Checkout our Interview prep page, It might help you.
My interests
As a techie + proud Hindhu i love to know/write about technology, spiritual knowledge.
Hey!, I am not living library. But if there is topic if you want me to cover, I will do my research and write about it, if it is unfamiliar to me. Its fun to learn and grow together.
Contact ID
Contact
author@luminari.info
© 2024. All rights reserved.
Well usually everyone goes with explaining containers and pod, like workloads but we feel it's better to know architectures first with those questions in the head. we will explain about work loads but now lets jump in with architecture and components.
Well usually everyone goes with explaining containers and pod, like workloads but we feel it's better to know architectures first with those questions in the head. we will explain about work loads but now lets jump in with architecture and components.