Issues with a if/else loop in Python

前端 未结 6 1849
萌比男神i
萌比男神i 2020-12-04 03:37

I am trying to make this Pig Latin translator in Python and it was working well until I tried to downsize it a bit.

Can someone please take a look at this code and t

6条回答
  •  执念已碎
    2020-12-04 04:21

    The if is alwasys returning True!

    pyg = 'ay'
    
    original = raw_input('Enter a word: ')
    low_original = original.lower()
    
    if len(low_original) > 0 and low_original.isalpha():
        print low_original
        if low_original[0] in ['a' , 'e' , 'i' , 'o' , 'u']:
                print "vowel"
                pyg_vowel = low_original + pyg
                print pyg_vowel
        else:
                print "consonant"
                pyg_cons = low_original[1: ] + low_original[0] + pyg
                print pyg_cons
    else:
        print 'empty'
    

提交回复
热议问题