''' Purpose: use if-else statement ''' # Python if statement: # if (condition): # do this # elif (condition): # do this # else: # NO CONDITION (basically says if we didn't jump into any other condition, do this!) # do this # Once it meets a certain condition, it jumpts into that block and doesn't test the ones after it. # This is super important because you want to make sure your tets / condition testing is in the right order # so that you don't jump into a certain conditional block (indented if/elif block) if it should test # another one before it. # define helpful constant VOWELS = "aeiou" # get input text and put into canonical form text = input( 'Enter text: ' ) text = text.strip() text = text.lower() # determine its first character first_character = text[0] # print('first character:', first_character ) # determine whether first character is a vowel # This loop IS going through every vowel. It just won't jump into the if block for all the vowels # right because we're only checking the first character and the first character can't be # all five vowels :) # Loop version for vowel in VOWELS: # Loop through each character vowel in VOWELS ('a',then 'e', then 'i', etc.) if (first_character == vowel): # if the first character matches the vowel we're on print('First character begins with a vowel!') else: pass # do nothing (move onto the next value in the for loop) # else: # This else statement gets executed for all of the other characters! We don't want that! # print('First character does NOT begin with a vowel!') # Since the other characters aren't vowels # You don't need an else if you have an if statement. # You can do: # if (): # do this # if (): # do this # else: # do this # if(): # do this # elif(): # do this # else: # do this # without a Loop # if ( first_character in VOWELS ): # if the first character is in the string 'aeiou' (if it's one of the vowels in the string!) # print('First character begins with a vowel!') # else: # print('First character does NOT begin with a vowel!') # Recall the in keyword will check if the thing on the left is in the sequence on the right # if (... in sequence): # if (... not in sequence): # checks if the thing on the left is NOT in the sequence on the right # VOWELS 'aeiou' # first_character 'a' # if (first_character in VOWELS): -> if 'a' in 'aeiou' (it is!) this evaluates to True so we # jump into that block and print out that the 'First character begins with a vowel!'