2 回答
TA贡献1876条经验 获得超6个赞
你最好用 in
if len(original) and original.isalpha():
word = original.lower()
first = word[0]
print first
if first in ('a','e','i','o','u'):
print "vowel"
else:
print "consonant"
你也做错了,如果你试图使用OR子句你必须使用这样但是它不是更好的pythonic方式:
if first =='a' or first =='e' or first =='i' or first =='o' or first =='u':
TA贡献1862条经验 获得超6个赞
if str(first) == "a" or "e" or "i" or "u" or "o":
应该修改为
if str(first) in ("a", "e", "i", "o", "u"):
Python对缩进有明确的要求。确保你有一个正确的缩进。
original = raw_input('Enter a word:')
if len(original) > 0 and original.isalpha():
word = original.lower()
first = str(word)[0]
print first
if str(first) in ("a", "e", "i", "o", "u"):
print "vowel"
else:
print "consonant"
添加回答
举报