Last active
December 25, 2015 17:39
-
-
Save CaryInVictoria/7015199 to your computer and use it in GitHub Desktop.
is_a_vowel problem
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def is_a_vowel(c): | |
return c.lower() in "aeiou" | |
# or | |
def is_a_vowel(c): | |
return "aeiou".find(c.lower()) != -1 | |
# or | |
def is_a_vowel(c): | |
import re # Can be before def | |
regexp = re.compile(".*[aeiou].*") | |
if regexp.search(c.lower()): | |
return True | |
else: | |
return False | |
def report_if_vowel(c): | |
if is_a_vowel(c): | |
print('Yup, \'{0}\' is a vowel'.format(c)) | |
else: | |
print('Nope, \'{0}\' ain\'t no vowel'.format(c)) | |
report_if_vowel('i') # => Yup, 'i' is a vowel | |
report_if_vowel('E') # => Yup, 'E' is a vowel | |
report_if_vowel('s') # => Nope, 's' ain't no vowel | |
report_if_vowel('J') # => Nope, 'J' ain't no vowel | |
report_if_vowel('%') # => Nope, '%' ain't no vowel |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment