+ 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 Antworten
+ 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"};