Created
May 18, 2019 13:34
-
-
Save Pirognoe/3d481cc8f0a758089d5ed8c7b2e9a29f 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
| def convert_to_words(input_message): | |
| # Vocabulary | |
| words = { | |
| '0': 'zero', | |
| '1': 'one', | |
| '2': 'two', | |
| '3': 'three', | |
| '4': 'four', | |
| '5': 'five', | |
| '6': 'six', | |
| '7': 'seven', | |
| '8': 'eight', | |
| '9': 'nine', | |
| '10': 'ten', | |
| '11': 'eleven', | |
| '12': 'twelve', | |
| '13': 'thirteen', | |
| '=': 'equals', | |
| '-': 'minus', | |
| '+': 'plus', | |
| '*': 'times', | |
| '/': 'divided by', | |
| '.': 'point', | |
| ',': 'comma', | |
| ' ': ' ' | |
| } | |
| # Check if the input message is valid | |
| if type(input_message) == str: | |
| print(input_message) | |
| digits = input_message.split() | |
| print(digits) | |
| for element in digits: | |
| if len(element) <= 1: | |
| input_message = input_message.replace(element, words[element]) | |
| elif len(element) == 2: | |
| print (element, words[element]) | |
| # input_message = input_message.replace(element, words[element]) | |
| return input_message | |
| else: | |
| return 'invalid input' | |
| print(convert_to_words(1)) | |
| print(convert_to_words('3 + 7 = 10')) | |
| print(convert_to_words('5 * 7 = 35')) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment