+ 5
[SOLVED] Code Coach: No Numerals. 1/6 Tests Failed.
#My Code txt = input() a = {'1':'one','2':'two', '3':'three','4':'four','5':'five','6':'six','7':'seven','8':'eight','9':'nine','0':'zero', '10':'ten'} for i in txt: if i in a: txt = txt.replace(i, a[i]) print(txt) #How to get all the results correct?
19 Respuestas
+ 1
Edited works
#Code Coach: No Numerals. 1/6 Tests Failed.
#My Code
txt = input()
tx=txt.split(" ")
a = {'1':'one','2':'two', '3':'three','4':'four','5':'five','6':'six','7':'seven','8':'eight','9':'nine','0':'zero','10':'ten'}
for i in tx:
if i in a:
txt = txt.replace(i, a[i])
print(txt)
#How to get all the results correct?
+ 2
maf you can try this also..
a=input("")
d={"1":"one","2":'two',"3":'three',"4":'four',"5":'five',"6":'six',"7":'seven',"8":'eight',"9":'nine',"10":'ten',"0":'zero'}
x=a.split(' ')
for i in x:
if i in d.keys():
u=x.index(i)
x[u]=d[i]
o=" ".join(x)
print(o)
+ 2
🙂🙂
+ 2
numbers = {
'0': 'zero', '1': 'one', '2': 'two',
'3': 'three', '4': 'four', '5': 'five',
'6': 'six', '7': 'seven', '8': 'eight',
'9': 'nine', '10': 'ten',
}
phrases = input() # i need 2 pumpkins and 3 apples
result = ''
for i in phrases.split():
result += (numbers.get(i, i) + ' ')
print(result)
+ 2
Welcome sir
+ 1
You forgot 10. There's test case that checks for number 10.
+ 1
Use reg ex
import re
txt = input()
a = {'1':'one','2':'two', '3':'three','4':'four','5':'five','6':'six','7':'seven','8':'eight','9':'nine','10':'ten', '0':'zero'}
new_txt = re.sub('(\d+)', lambda m: a[m.group()], txt)
print(new_txt)
+ 1
Using replace() function for each character won't work for example, if the string is
'10 times better'
replace() will transform it to 'onezero times better' because it works at character level. That is why you need regular expressions
https://www.sololearn.com/learn/JUMP_LINK__&&__Python__&&__JUMP_LINK/2475/
+ 1
Justus thanku somuch, that works too :)
+ 1
RAJESH SAHU Ohh thats nice too, thnx
+ 1
Look maf it works...
https://code.sololearn.com/ctjE5Ff1qXwH/?ref=app
0
CarrieForle lol i thought that too, but no I tried that.
I have it in my code, i edited it out here in qs coz i thought 10 was not included xD
0
Ore Adeleye man thats pretty advanced xDD, can u please explain me that what was wrong in my code? And thanks to both for trying to help.
0
Ore Adeleye oooooh, thnku so much
0
Code Crasher thanks for explaining, Justus's way (similar to yours) was simpler and I got it easily, Ore Adeleye's way was more advanced.
0
Code Crasher lol yeah u r right. :)
after this ima learn some advanced stuff.
0
Thank u so much Syed Waseem and 🐍🗡️ R. S 💖 A. S🗡️🐉, I understood ur answers. :)