0

No Numerals Challenge

I can't get TestCase #3 right whatever configuration I do, but I think the problem is that when for example the input is "10 Cows where butchered today" instead of it staying as is, it changes to "onezero cows where butchered today" How do i fix this? I brains not braining length = [] for i in range(0,11): length.append(i) nums = { "0":"zero", "1":"one", "2":"two", "3":"three", "4":"four", "5":"five", "6":"six", "7":"seven", "8":"eight", "9":"nine", } text = input() for i in nums: if i in text: z = nums.get(i) text = text.replace(i, z) print(text)

24th May 2023, 1:16 PM
Adventure of Tol
Adventure of Tol - avatar
2 ответов
+ 8
Add "10" : "ten" into <nums> dictionary before the "0" : "zero" 10 needed to be checked before the 0 and 1 in order for the 10 -> "ten" replacement to work rather than to have the "one" "zero" in place of it. I did the task by splitting input string first, then check each chunk for an item in <nums>. If a chunk exists as a key in <nums>, replace it by the respective item value. But there are many ways to go to Rome, so you go your way : ) And I don't think you needed that <length> `list` anyway ...
24th May 2023, 2:45 PM
Ipang
+ 2
Ipang Thankyou, I appreciate your help
25th May 2023, 2:59 AM
Adventure of Tol
Adventure of Tol - avatar