#!/usr/bin/env python """ A second English to Openglopish translater. See oppish.py for what this is all about. This version uses a different approach, which among other changes 1. Builds the answer in a list rather than a string. 2. Loops over characters using an index. 3. Tests explicitly for uppercase vowels, and adds 'Op' when they're found. 4. Uses char[i-1] for the previous character, rather than remember it. 5. Does everything in one piece without subroutines. 6. Exits the main loop with the python 'break' instruction The big disadvantage of doing things without subroutines is that it's much more difficult to test, debug, or reuse. """ print " - - Openglopish 2 - - " print " Hit return to quit." vowels = ['a', 'e', 'i', 'o', 'u'] upper_vowels = ['A', 'E', 'I', 'O', 'U'] while True: line = raw_input('English : ') if line == '': break chars = list(' ' + line) new_chars = list() for i in range(1, len(chars)): if chars[i] in upper_vowels: chars[i] = chars[i].lower() new_chars.append('Op') elif chars[i] in vowels and not chars[i-1] in vowels: new_chars.append('op') new_chars.append(chars[i]) print 'Openglopish : ' + ''.join(new_chars)