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 for statements more written for word in alist: , for ltr in word: (i used variable word instead of c because think it's clearer). not need loop on integer value , index based on variable.
  • your outermost if/elif pair can more written if/else. there's no other possible route of execution.
  • your statements testing in vowels or in cons fail 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

Popular posts from this blog

user interface - How to replace the Python logo in a Tkinter-based Python GUI app? -

objective c - Greedy NSProgressIndicator Allocation -

how to set an OCR language in Google Drive -