I am new to Python. I am writing a program that distinguishes whether or not a word starts with a vowel. The problem is, that the program is only able to correctly handle uppercase letters as input. For example, if I provide the word "Apple" as input, the result is True
; however, if the word "apple" is provided as input, the result is False
. How do I fix it?
word = input ("Please Enter a word:")
if (word [1] =="A") :
print("The word begins with a vowel")
elif (word [1] == "E") :
print("The word begins with a vowel")
elif (word [1] == "I") :
print("The word begins with a vowel")
elif (word [1] == "O") :
print("The word begins with a vowel")
elif (word [1] == "U") :
print("The word begins with a vowel")
else:
print ("The word do not begin with a vowel")
Convert the word entirely to lowercase (or uppercase) first:
word = input("Please Enter a word:").lower() # Or `.upper()`
Also, to get the first letter of your word, use word[0]
, not word[1]
. Lists are zero-indexed in Python and almost all programming languages.
You can also condense your code by quite a bit:
word = input("Please Enter a word:")
if word[0].lower() in 'aeiou':
print("The word begins with a vowel")
else:
print("The word do not begin with a vowel")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With