This python code that I am running returns nothing but a blank string when I run it -
i tried running sentence... "can speak pig latin?"
def igpay(sentence): alist = sentence.split(" ") newsentence = "" vowels = "aeoiu" cons = "qwrtypsdfghjklzxcvbnm" in range(len(alist)): c = alist[i] if c[0] in vowels: = c + "way" newsentence += elif c[0] not in vowels: j in range(len(c)): f = c[j] if f in cons: o = c.replace(c[j],"") = c[j:j+1] b = o + if f in vowels: v = b + "ay" newsentence += v return(newsentence)
the reason you're seeing nothing neither of lines newsentence += never reached.
the first line never reached because there no words begin vowels.
the second line never reached because test if f in vowels never executed unless if f in cons known true. think may possibly have indentation error here.
a few other notes:
- your 2
forstatements more writtenfor word in alist:,for ltr in word:(i used variablewordinstead ofcbecause think it's clearer). not need loop on integer value , index based on variable. - your outermost
if/elifpair can more writtenif/else. there's no other possible route of execution. - your statements testing
in vowelsorin consfail upper-case letters. - your replace() call replace all instances of vowel, not first one. (i'm not entirely sure you're trying here, strip off initial consonant , place on end?)
Comments
Post a Comment