1

I'm pondering if I could convert this line of code into a list for all these vowels;

if first== 'a' or first =='e' or first == 'i' or first == 'o' or first =='u':"

I'm thinking str[a,e,i,o,u]

pyg = 'ay'
first = original[0]
original = raw_input('Enter a word:')

if len(original) > 0 and original.isalpha():
    print original.lower()
    if first== 'a' or first =='e' or first == 'i' or first == 'o' or first =='u':
        print "vowel"
    else:
        print "consonant"
else:
    print 'empty'


word = original
1
  • 3
    You should probably move first = original[0] after original = raw_input('Enter a word:') Commented Sep 13, 2013 at 2:15

4 Answers 4

1
if first.lower() in ['a','e','i','o','u']:
    print "vowel"
else:
    print "consonant"

I think the word you are looking for (Beuller) is Boolean?

Sign up to request clarification or add additional context in comments.

Comments

0

You can use a string instead of a list:

if first in "aeiou":
   print "vowel"
else:
   print "consonant"

Bear in mind that your current code prints the first letter in lowercase, but doesn't actually change it to lowercase. You could use:

if first.lower() in "aeiou":

1 Comment

Because a string is semantically a list of characters, and Python wants to make things easy for you.
0

In Python, str types are like list types in many ways. One of those ways is that the simple and succinct in keyword works just fine for testing membership in both.

pyg = 'ay'
first = original[0]
original = raw_input('Enter a word:')

if len(original) > 0 and original.isalpha():
    print original.lower()
    if first in 'aeiou':
        print "vowel"
    else:
        print "consonant"
else:
    print 'empty'


word = original

Comments

0

You have a few problems here:

first = original[0]
original = raw_input('Enter a word:')

You're trying to access original before it's defined, this is a simple fix, as it says in the comment (+1 DaoWen), just swap those two lines.

However, then you check to make sure something was entered:

if len(original) > 0

But by then, if original doesn't pass that statement, it will have thrown an error with first = original[0], so it may be better to hold off assigning first until you're in the if block:

original = raw_input('Enter a word:')

if len(original) > 0 and original.isalpha():
    print original.lower()
    first = original[0].lower()
    if first in ['a','e','i','o','u']: print "vowel"
    else: print "consonant"
else:
    print 'empty'

word = original

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.