lundi 20 avril 2015

I can't return a value

I'm trying to write a function that will translate the input into so-called "cow Latin." I want to return the values from the if statement but whenever I do I get a syntax error. I can print the value but I want to avoid the function returning None as well.

def cow_latinify_sentence(sentence):
    vowels = tuple('aeiou1234567890!@#$%^&*()-_=+|\\][}{?/.\',><`~"')
    sentence = sentence.lower()
    sentence_list = sentence.split()
    for i in range(len(sentence_list)):
        cow_word = sentence_list[i][:]
        if cow_word.startswith(vowels):
            print('{0}moo'.format(cow_word), end=' ')
        else:
            cow_word = sentence_list[i][1:] + sentence_list[i][:1]
            print('{0}oo'.format(cow_word), end=' ')

cow_latin = cow_latinify_sentence("the quick red fox")
print(cow_latin)

In short, how can I get the function to return instead of print?

Aucun commentaire:

Enregistrer un commentaire