+ 8
Code coach question
How do we replace a number in a sentence with the relevant name of that number? (eg:- I have 3 pens-> I have three pens)
5 Answers
+ 8
Thank you very much
+ 7
[Edited *]
Kalindu Wanasinghe(Not Yet) , you could do it with string replace() but there is also an other way to do it. (python)
âȘïž put all your numerals in a dictinary as key : value pair like {1: "one", ...}
âȘïž split the input sentence to a list
âȘïž iterate over that list by using a for loop and check if the current word is in the dictionary
âȘïž if YES, use this word to find the keyword and use the value of it to replace the current element of the list
âȘïž in NO, continue in looping
âȘïž*if looping is finished, the elements of the list can be put together with join() to a string for output
+ 4
make an array of that number range names .
a=["zero","one","two"]
and when looping over string you encounter an integer ,use it as an index to get relevant name from that array a .
+ 1
That is correct
0
Create array of numbers like
Num[]={"no","one",... "ten"};