Jump to content
Sal's RuneScape Forum
  • entries
  • comments
  • views

Is there anybody here who can help a python newbie?



I'm supposed to be writing a program that translates a sentence to 'cow latin' (pig latin except changed slightly for this assignment). I've written a function that converts singular words, but I'm not sure how to proceed in applying that to entire sentences. I know it's to do with using the split function but I don't know how to apply that to my code.


Recommended Comments

So I've never worked with python (c++ here) but maybe you could try to do some sort of loop and call the function on each word in the sentence. I don't know how that translates into python syntax though, sorry.

Share this comment

Link to comment

Yeah, I kinda know the basis of what I have to do, I just don't know how to do it.

Share this comment

Link to comment

You'd make a main function that would accept a string and in that function you would go through each word and apply to it whatever function would be appropriate.


You can get a list of a text string by using split(), so

text = "Foo bar nux"
> ['Foo', 'bar', 'nux']


So you could use a for loop and go through each word.

text = "Foo bar nux"
for x in range (0, len(text.split())):
print text.split()[x]

And you'll get each individual word printed back. Applicable for everything, including your function.


As a side note, sounds like you're way past needing this but I learned using this (I took Java and C++ and am moving onto Haskell, wasn't able to do Python in school) and I recommend it all the time.

Share this comment

Link to comment

Appreciate the help, but I ended up getting a hand from a friend. Cheers though

Share this comment

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Important Information

By using this site, you agree to our Guidelines and Privacy Policy.