Skip to content

Instantly share code, notes, and snippets.

@accessnash
Created October 19, 2015 07:30
Show Gist options
  • Select an option

  • Save accessnash/b4145bfe382f6500a04e to your computer and use it in GitHub Desktop.

Select an option

Save accessnash/b4145bfe382f6500a04e to your computer and use it in GitHub Desktop.
""" A program to change case using functions """
import sys
def caps_case(text):
"""Returns the 1st character capitalized"""
print(text.capitalize())
def title_case(text):
"""Returns the 1st letter of all words capitalized"""
print(text.title())
def upper_case(text):
"""Returns the whole text in UPPER case"""
print(text.upper())
def lower_case(text):
"""Returns the whole text in lower case"""
print(text.lower())
def exit(text):
"""Ends the program."""
print("Goodbye for now!")
sys.exit()
if __name__ == "__main__":
caser = {
'capitalize': caps_case,
'title': title_case,
'upper': upper_case,
'lower': lower_case,
'exit': exit
}
options = caser.keys()
prompt = 'Pick an option from the list ({0}): '.format(', '.join(options))
#text = input("Please enter a string: ")
while True:
inp = input(prompt)
text = input("Please enter a string: ")
option = caser.get(inp, None)
if option:
option(text)
else:
print('Please select a valid option!')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment