Is there any way in python that we can print string equivalent of the digit entered?
For eg. if the user inputs '8' the output should be 'Eight', if the input is '15', the output should be 'fifteen'.
Any help will be appreciated. Thanks
Is there any way in python that we can print string equivalent of the digit entered?
For eg. if the user inputs '8' the output should be 'Eight', if the input is '15', the output should be 'fifteen'.
Any help will be appreciated. Thanks
You can use the num2words library to convert numbers into words ( https://pypi.org/project/num2words )
Here is a code example that requests user input and print the output in words.
from num2words import num2words
num = input('Enter number: ')
print(num2words(num))
Sample output:
Enter number: 42
forty-two
Hope this helps.
Does this answer your question:
def dict_of_numbers():
dictionary = {}
numbers = []
for initialise in range(100):
numbers.append(initialise)
#print(numbers)
word0 = ['zero']
wordints = ['one', 'two', 'three','four', 'five', 'six','seven', 'eight', 'nine']
wordteens = ['ten', 'eleven', 'twelve', 'thirteen', 'fourteen',
'fifteen', 'sixteen', 'seventeen', 'eighteen', 'nineteen']
wordtens = ['twenty', 'thirty', 'forty', 'fifty', 'sixty', 'seventy', 'eighty', 'ninety']
rest = []
for i in range(len(wordtens)):
rest.append(wordtens[i])
for j in range(len(wordints)):
rest.append(wordtens[i] + "-" + wordints[j])
wordListFinal = []
wordListFinal.append(word0[0])
for i in wordints:
wordListFinal.append(i)
for i in wordteens:
wordListFinal.append(i)
for i in rest:
wordListFinal.append(i)
#print(wordListFinal)
dictionary = {numbers[i] : wordListFinal[i] for i in range(len(numbers))}
return dictionary