What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Skype & Technology » Tech Talk » python functions wft

python functions wft
Author: Message:
Jarrod
Veteran Member
*****

Avatar
woot simpson

Posts: 1304
Reputation: 20
– / Male / Flag
Joined: Sep 2006
O.P. Undecided  python functions wft
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?

This post was edited on 08-03-2008 at 12:00 AM by Jarrod.

[Image: 5344.png]
[Image: sig.png]

A.k.a. The Glad Falconer














08-02-2008 11:58 PM
Profile E-Mail PM Find Quote Report
« Next Oldest Return to Top Next Newest »

Messages In This Thread
python functions wft - by Jarrod on 08-02-2008 at 11:58 PM
RE: python functions wft - by segosa on 08-03-2008 at 01:37 AM
RE: python functions wft - by Jarrod on 08-03-2008 at 01:53 AM
RE: python functions wft - by ShawnZ on 08-03-2008 at 10:01 AM
RE: python functions wft - by Mnjul on 08-03-2008 at 10:07 AM
RE: python functions wft - by Jarrod on 08-03-2008 at 11:14 AM
RE: python functions wft - by foaly on 08-03-2008 at 11:54 AM


Threaded Mode | Linear Mode
View a Printable Version
Send this Thread to a Friend
Subscribe | Add to Favorites
Rate This Thread:

Forum Jump:

Forum Rules:
You cannot post new threads
You cannot post replies
You cannot post attachments
You can edit your posts
HTML is Off
myCode is On
Smilies are On
[img] Code is On