Break it Down


Just wanted to post how I got the first part of the pyglatin to work. Pretty sure its not the sleekest code but it works. I pretty much looked back at earlier lessons and modeled it off them.
Any feedback would be appreciated, thanks.

def pyglatin():
    print "Give me an English word and I'll give you the Pyglatin translation!!"
    word = raw_input().lower()
    if len(word) == 0:
        print "Oops, you gota push the key(s) a bit harder."
    elif len(word)>1:
        headless_word = word[1:]
        first_letter_of_word = word[0]
        pyglatin_special_sauce = "ay"
        print headless_word+first_letter_of_word+pyglatin_special_sauce
        print word + "ay"


Single-letter words aren't a special case, are they?

And if you're making a function, then it would be better that it take input through arguments and returns the result. Your function both communicates with the outside and transforms the string, it's doing too much.

Your function also calls itself, should it really be doing recursion? This is particularly weird when also doing input/output and it also does it only for single character words. I get that it's a way of accomplishing a re-prompting for input, but it would be less of a tangle to separate that out from the function that translates


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.