+ 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.
11 odpowiedzi
+ 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))
+ 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;
+ 3
Please show you attempt
+ 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' ^^
+ 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
0
What do I do then? Visph
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
0
Tharul Nejana
Thanks
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
- 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))