i'm trying to write a python function which takes the string "s" and turns in a string or integer from an English representation, for example:
five six nine
will return
569
i wrote all the code to do it, and it looks like this
code:
s = raw_input("what is the string")
s = s.replace('one','1')
s = s.replace('two','2')
s = s.replace('three','3')
s = s.replace('four','4')
s = s.replace('five','5')
s = s.replace('six','6')
s = s.replace('seven','7')
s = s.replace('eight','8')
s = s.replace('nine','9')
s = s.replace('zero','0')
s = s.replace(' ','')
s = s.strip()
s = s
print s
now when i turn it into a function is should look like this
code:
s = raw_input("what is the string")
def words2number(s):
while 1:
s = s.replace('one','1')
s = s.replace('two','2')
s = s.replace('three','3')
s = s.replace('four','4')
s = s.replace('five','5')
s = s.replace('six','6')
s = s.replace('seven','7')
s = s.replace('eight','8')
s = s.replace('nine','9')
s = s.replace('zero','0')
s = .replace(' ','')
s = s.strip()
s = s
return s
words2number(s)
but my return does not work can someone explain the technicalities of that to me?