Created
October 19, 2015 07:30
-
-
Save accessnash/b4145bfe382f6500a04e to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| """ 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