Created
May 14, 2018 13:32
-
-
Save innat/2859541755f7713e32d8e66be2d80173 to your computer and use it in GitHub Desktop.
encrypt language :P
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
| # One Way | |
| word_string = input("Input a word: ") | |
| while word_string[0].lower() not in ['a','e','i','o','u']: | |
| word_string = word_string[1:] + word_string[0:1] | |
| else: | |
| print(word_string + 'ay') | |
| # Another way | a bit more complicated | |
| VOWELS = ('a', 'e', 'i', 'o', 'u') | |
| def convert_word(word): | |
| first_letter = word[0] | |
| if first_letter in VOWELS: # if word starts with a vowel... | |
| return word + "hay" # then keep it as it is and add hay to the end | |
| else: | |
| return word[1:] + word[0] + "ay" # like the lab mentions, word[1:] | |
| # returns the word except word[0] | |
| # From this function, it's easy to take a sentence and convert it to Pig-Latin. | |
| def convert_sentence(sentence): | |
| list_of_words = sentence.split(' ') | |
| new_sentence = "" # we'll keep concatenating words to this... | |
| for word in list_of_words: | |
| new_sentence = new_sentence + convert_word(word) # ...like this | |
| new_sentence = new_sentence + " " # but don't forget the space! | |
| return new_sentence | |
| # Now, let's write the main program code, to ask the user and convert. | |
| print("Type in a sentence, and it'll get converted to Pig-Latin!") | |
| print("Please don't use punctuation or numbers.") | |
| print("So lowers only please!") | |
| text = input('Say Something :- ') # nothing in the parentheses, because there's nothing else | |
| # extra to tell the user before he is allowed to type | |
| print(convert_sentence(text)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment