+ 1
It's a start, but it needs work. There is a problem when it comes to looking for '10'. Checking one character at a time won't work. Nor will it work to expand the check to two characters, because then what happens when it encounters '100'? Or '1st'? A full solution requires comparing whole words. The split() string method comes in handy to break up the input by spaces.
31st Jul 2022, 5:06 AM
Brian
Brian - avatar
+ 1
Sobola Gabriel think further about what happens with the global replacement approach. Input: 2010 Output should be 2010. But instead, after the blind replacements the output is: -> 20ten -> two0ten -> twozeroten It doesn't work.
1st Aug 2022, 5:46 PM
Brian
Brian - avatar
+ 1
Brian what you tells the program to do for you is to replace numbers from 10 downward with their equivalents words so 2010 would be seen as twozeroten and not a single no as two thousand and ten( 2010)
1st Aug 2022, 9:29 PM
Sobola Gabriel
Sobola Gabriel - avatar
+ 1
Sobola Gabriel I tested your sentence, "This is machie3456nd to have34 yo2r to 10 pla2ce", with my Code Coach solutions in five languages and got correct output from each one: "This is machie3456nd to have34 yo2r to ten pla2ce" Like most things, the solution is easy when you know how. A simple solution in Python takes only five lines of code. Use a dictionary, the input function, the split function, a while loop, one if statement and a print statement.
2nd Aug 2022, 7:28 AM
Brian
Brian - avatar
0
Janne using the simple .replace on the whole string also fails when the input includes "100" or "1st".
1st Aug 2022, 7:43 AM
Brian
Brian - avatar
0
I think accounting for the "10" in the phrase is a good way to start by first replacing all 10s with "ten" then others follow
1st Aug 2022, 3:38 PM
Sobola Gabriel
Sobola Gabriel - avatar
0
Sobola Gabriel the task is to replace only numbers that are "10 and under", since 2010 > 10 it is not to be replaced at all.
2nd Aug 2022, 12:14 AM
Brian
Brian - avatar
0
Brian for files for with nos greater than 10 that are few say like (10 - 20) of them, one might need to first replace those nos by other characters (say "#', "*", "?", etc) thereafter proceeds to first replacing 10, then others, and finally replace the "#", "*", "?", etc by the large nos equivalent. But this won't be possible on large files. If you considering your solution up there(breaking the input by spaces) then some of the elements of the input (large nos) will have to stand alone, otherwise if you have something like "This is machie3456nd to have34 yo2r to 10 pla2ce", you know it might not be possible.
2nd Aug 2022, 6:53 AM
Sobola Gabriel
Sobola Gabriel - avatar
0
Brian definitely your code is going to work perfectly with that sentence, what if 3456 is a single number standing alone. Won't your code change it to threefourfivesix?
2nd Aug 2022, 4:19 PM
Sobola Gabriel
Sobola Gabriel - avatar
0
Sobola Gabriel "3456" will work just as well because when it converts the whole word to a numeric value, it is greater than 10 (more specifically, the number is not found in the dictionary keys) so the word passes through without being replaced.
2nd Aug 2022, 5:40 PM
Brian
Brian - avatar
0
Brian great work by you 👍 then
2nd Aug 2022, 6:19 PM
Sobola Gabriel
Sobola Gabriel - avatar
- 1
Take the string as an input and do string = string.replace("1", "one") etc
 But replace at first because otherwise the program will replace 1 and 0 to one zero instead of ten
1st Aug 2022, 3:39 AM
Janne
Janne - avatar