Skip to content

Instantly share code, notes, and snippets.

@CaryInVictoria
Last active December 25, 2015 17:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save CaryInVictoria/7015199 to your computer and use it in GitHub Desktop.
Save CaryInVictoria/7015199 to your computer and use it in GitHub Desktop.
is_a_vowel problem
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