vowels = 'aieou' samepast = ['hit','cost','spread','cut', 'put', 'let', 'hurt', 'quit', 'read', 'broadcast'] #List of words that are the same in both tenses irrpast = {'go':'went', 'break':'broke', 'buy':'bought', 'sit':'sat', 'eat':'ate', 'come':'came', 'sleep':'slept', 'see':'saw', 'pay':'paid', 'sing':'sang', 'tell':'told', 'get':'got','teach':'taught', 'feel':'felt', 'hear':'heard' } #Dictionary of irregular verbs and their irregular past forms def isLikeTap(wd): longCons = 'xwy' #These are the letters you want to exclude vowelCount = wd.count('a') + wd.count('e') + wd.count('i') + wd.count('o') + wd.count('u') if vowelCount == 1 and wd[-1] not in vowels + longCons: #concatenate the two sets - easier than doing two "and" clauses return True else: return False #Implemented getting past tense as a separate function #Uses negative indexing to get the last characters of words def getPastTense(w): if w in samepast: #checks simplest case first past = w elif w in irrpast: past = irrpast[w] #gets irregular form from the dictionary elif isLikeTap(w) == True: past = w + w[-1] + 'ed' elif w[-2] not in vowels and w[-1] == 'y': past = w[:-1] + 'ied' #string slicing to get everything except the last character - w[:-1] is the same as w[0:-1] elif w[-1] == 'e': past = w + 'd' else: past = w + 'ed' return past #returns the past tense string I've built up prompt = raw_input('What are your verbs? (Type EXIT to quit): ') #Starts off the prompting while(prompt != 'EXIT'): words = prompt.split() #splits the words given into a list so it can work on each one for w in words: past = getPastTense(w) #calls the past tense function - just like calling a built in function! print w, past prompt = raw_input('What are your verbs? (Type EXIT to quit): ') #Have to put this here to continue the loop print "Thank you for using the Past Tense Generator. Goodbye."