r/learnpython • u/tired_papasmurf • Jun 23 '13
Anybody know why my code will not read the second If Statement?
I was making a code as part of the CodeAcademy's learning Python thing and it wants to make a Pig Latin Translator.
The code works fine up until I want to check to see if the first letter is a vowel on Line 6. The code just prints "vowel", regardless of whether the word I type in is "angus" or "piggy". I've switched the "==" to a "!=" just to see if it would change anything; it didnt. This makes me think that the code isn't reading the If Statement?
I know that word[0] is working and its accurate, I just dont know if my syntax is wrong/stupid. Any help would be appreciated. (Also its unfinished, just so you know).
pyg = 'ay'
original = raw_input('Enter a word:')
if len(original) > 0 and original.isalpha():
word = original.lower()
if word[0] == "a" or "e" or "i" or "o" or "u":
print "vowel"
else:
print "consonant"
else:
print 'empty'
6
Upvotes
12
u/K900_ SRE person // please don't DM me your questions Jun 23 '13
if word[0] == "a" or "e" or "i" or "o" or "u":You think it is
if word[0] == ("a" or "e" or "i" or "o" or "u"):, but it's not. It'sif (word[0] == "a") or "e" or "i" or "o" or "u":."e"is a non-empty string, so it's truthy. So the whole condition is truthy. To check if an object is in a sequence, usein, like this:if word[0] in "aeoiu":