#!/usr/bin/env python """ Convert English to Openglopish. The rules we'll use are : * Insert 'op' before each consecutive string of vowels. * Preserve capitalization of words. This isn't, I think, quite 'standard' Openglopish (if there is such a thing), but close enough for this exercise. See http://en.wikipedia.org/wiki/Opish for details on this 'language game'. This file was put together for a demo for a python programming course. Jim Mahoney, Marlboro College, Oct 2006 """ def is_vowel(character): """ Return true if the character is a vowel. """ vowels = ['a', 'e', 'i', 'o', 'u'] return character in vowels def openglopish_line(line): """ Translate a line from english to openglopish. """ english_words = line.split() openglopish_words = [] for word in english_words: openglopish_words.append(openglopish_word(word)) return ' '.join(openglopish_words) def openglopish_word(word): """ Translate a word from english to openglopish. """ word_is_capitalized = word.istitle() word = word.lower() new_word = '' previous_character = '' for character in word: if is_vowel(character): if not is_vowel(previous_character): new_word = new_word + 'op' new_word = new_word + character previous_character = character if word_is_capitalized: new_word = new_word.capitalize() return new_word def main(): """ For each line typed by the user, print both the line and its openglopish translation. """ print " - - Openglopish - - " print " Hit return to quit." done = False while not done: line = raw_input('English : ') if line == '': done = True else: print 'Openglopish : ' + openglopish_line(line) main()