how to get my while to update a string length in python -


i'm trying while loop working remove consonants front of input word, goes through once , finishes, how keep while loop going until consonants @ end of word (example: want "switch" "itch + sw" , to, once consonants moved, add "ay" @ end form "itchsway" here code far, i'm new python appreciated!

print("pig latin translator test!") name = raw_input("what name?") if len(name) > 0 , name.isalpha():     print("hello!") else:     print("that's not name!") word = raw_input("what word?") word0 = word[0] word0 = word0.lower() n = 0 if len(word0) > 0 , word0.isalpha():     word0proof = word0 else:     print("that isn't word!") if word0proof in "aeiou":     wordoutput = word + "yay"     print (wordoutput) else:     print("your word doesn't begin vowel") if word0proof in "bcdefghjklmnpqrstvwxyz":     word1 = word0proof else:     word0proof = word0proof #now word1 move consonants of word , add "ay" 

this part i'm having trouble in code

while word1 in "bcdefghjklmnpqrstvwxz":     word1 = word[n:] + word0 + "ay"     n = n + 1     print word1     word1 = word1 

aside indention issues, stole ideas @ improving code , got (removed variables , and borrowed while statement provided vowel list)

print("pig latin translator test!") name = raw_input("what name, friend?") if len(name) > 0 , name.isalpha():     print("hello!") else:     print("that's not name!") word = raw_input("what word?") vowels = ("a", "e", "i", "o", "u", "a", "e", "i", "o", "u") if word[0] in vowels:     word = word + "yay" else:     while word[0] not in vowels:         word = word[1:] + word[0]     word = word + "ay" print (word) 

as others have mentioned, need fix indentation , possibly consider tackling question in different manner.

to directly answer question:

while word[0].lower() not in "bcdefghjklmnpqrstvwxz":     word = word[1:] + word[0] word = word + "ay" 

you want add "ay" after loop finishes, or end multiple "ay"'s

here example of loop integrated simplified version of code.

vowels = ("a", "e", "i", "o", "u", "a", "e", "i", "o", "u") word = raw_input("please enter word: ") if word[0] in vowels:     word = word + "ay" else:     while word[0] not in vowels:         word = word[1:] + word[0]     word = word + "ay" print (word) 

Comments

Popular posts from this blog

OpenCV OpenCL: Convert Mat to Bitmap in JNI Layer for Android -

android - org.xmlpull.v1.XmlPullParserException: expected: START_TAG {http://schemas.xmlsoap.org/soap/envelope/}Envelope -

python - How to remove the Xframe Options header in django? -