0

Numbers into words

Enter number: 0 Number Entered: zero How do I do this????!

22nd Sep 2019, 5:40 PM
Shaun Blue
Shaun Blue - avatar
6 Respostas
+ 4
Go to code section (where you see codes created by other users) and at the top you will find search bar. Type : numbers words, and you will find many different codes that will give you idea how to do it by yourself.
22nd Sep 2019, 5:57 PM
voja
voja - avatar
+ 2
If you only want to support 1 digit as: Enter number: 1 Numbers Entered: one Enter number: 5 Numbers Entered: five Enter number: 11 Numbers Entered: ??? it is very easy. You could use: a list, a dictionary or a railed if-elif statement. If you want to support multiple digits as: Enter number: 6 Number Entered: six Enter Number: 30 Numbers Entered: three zero Enter Number: 123456789 Numbers Entered: one two three ... nine Then in addition you would need a loop: a for loop, a while loop, or a recursive function. The most problematic part would be to make it print: Enter number: 10 Number Entered: ten Enter number: 314159 Number Entered: three hundred fourteen thousands hundred fifty nine You do not need to focus on the last one yet.
22nd Sep 2019, 6:24 PM
Seb TheS
Seb TheS - avatar
+ 1
I think that it is possible to write all variants of words and matching numbers in two arrays (for example, from 0 to 100) and depending on the entered number output the result. am I wrong? that's not how it works? then function in a loop program and looking for matching numbers and words, then print the desired result.
22nd Sep 2019, 7:21 PM
Yaroslav Vernigora
Yaroslav Vernigora - avatar
+ 1
Not sure if this helps, but it might point you in the right direction:- numdict = dict(enumerate(['zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'ten'])) #etc x = int(input('Type in a number:- ')) try: print(numdict[x]) except KeyError: print("Error:- Out of range.")
22nd Sep 2019, 7:45 PM
rodwynnejones
rodwynnejones - avatar
0
or learn how dictonaries work in python, and use one gigantic one
22nd Sep 2019, 6:06 PM
Anton Böhler
Anton Böhler - avatar
0
A program simple enough to do single digits will go like this: n=int (input ('Enter a digit')) if a==0: print ('Entered number:Zero') if a==1: print ('Entered number:one') And so on
8th Jan 2020, 4:27 AM
Sourav Nanda
Sourav Nanda - avatar