Can someone help with No numerals code coach? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Can someone help with No numerals code coach?

I tried using for loop and if statements but it only executes the first statements and leaves the rest.

22nd Jun 2021, 11:56 AM
Francis Omane Asirifi
Francis Omane Asirifi - avatar
11 Answers
+ 6
Check out 👇 phrase = input().split() dict = {"0":"zero", "1":"one", "2":"two", "3":"three", "4":"four", "5":"five", "6":"six", "7":"seven", '8':"eight", "9":"nine", "10":"ten"} print(" ".join(dict.get(w,w) for w in phrase))
23rd Jun 2021, 2:33 PM
Tharul Nejana
Tharul Nejana - avatar
+ 4
Francis Omane Asirifi , ok - have you already done a try by yourself? if not - please do so. we need to see your code to get an idea on what the issue is. in any case: please put your code in playground and link it here. thanks and happy coding;
22nd Jun 2021, 1:29 PM
Lothar
Lothar - avatar
+ 3
Please show you attempt
22nd Jun 2021, 12:06 PM
SammE
SammE - avatar
+ 1
i take each char one by one, so i can never equals '10' (string of 2 char)... and even if it could, then 'one' should have replaced 1, so '10' now has becomed 'one0' ^^
22nd Jun 2021, 1:58 PM
visph
visph - avatar
+ 1
Tharul Nejana Thanks, i'm a newbie I was very prout of my code not using re print(" ".join(dict[w] if w in dict else w for w in phrase )) Until a saw yours
25th Jun 2021, 8:57 PM
Britz
0
What do I do then? Visph
22nd Jun 2021, 2:01 PM
Francis Omane Asirifi
Francis Omane Asirifi - avatar
0
one solution would be to remove if i=="10" statement, and replace first 10 in if i=="1", but wha for numbers greater than 10? you should find numbers of any digits numbers, and replace only those who are in the required range ;P
22nd Jun 2021, 2:08 PM
visph
visph - avatar
0
Tharul Nejana Thanks
23rd Jun 2021, 3:10 PM
Francis Omane Asirifi
Francis Omane Asirifi - avatar
0
Here's my solution: p = ("zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten") print(*map(lambda x: p[int(x)] if x.isdigit() else x, input().split())) # Hope this helps
24th Jun 2021, 8:55 AM
Calvin Thomas
Calvin Thomas - avatar
22nd Jun 2021, 1:48 PM
Francis Omane Asirifi
Francis Omane Asirifi - avatar
- 1
text = str(input()) for i in text: if i == "1": text = text.replace("1",'one') if i == "2": text = text.replace("2",'two') if i == "3": text = text.replace("3",'three') if i == "4": text = text.replace("4",'four') if i == "5": text = text.replace("5",'five') if i == "6": text = text.replace("6",'six') if i == "7": text = text.replace("7",'seven') if i == "8": text = text.replace("8",'eight') if i == "9": text = text.replace("9",'nine') if i == "10": text = text.replace("10",'ten') if i == "0": text = text.replace("0",'zero') print(str(text))
22nd Jun 2021, 1:54 PM
Francis Omane Asirifi
Francis Omane Asirifi - avatar