Here is the simple solution in Python:
def conjugate(verb): verb = verb.lower() ans = {} if (verb[-2] + verb[-1]) == 'ar': ans[verb] = [ verb[0:-2] + 'o', verb[0:-2] + 'as', verb[0:-1] + '', verb[0:-2] + 'amos', verb[0:-2] + 'ais', verb[0:-2] + 'an', ] if (verb[-2] + verb[-1]) == 'er': ans[verb] = [ verb[0:-2] + 'o', verb[0:-2] + 'es', verb[0:-1] + '', verb[0:-2] + 'emos', verb[0:-2] + 'eis', verb[0:-2] + 'en', ] if (verb[-2] + verb[-1]) == 'ir': ans[verb] = [ verb[0:-2] + 'o', verb[0:-2] + 'es', verb[0:-2] + 'e', verb[0:-2] + 'imos', verb[0:-2] + 'is', verb[0:-2] + 'en', ] return ans
Nice answer. Here is a suggestion that gets rid of the duplicate code by putting the verb endings in a dict and using a comprehension to give the result:
def conjugate(verb): verb = verb.lower() conj = { 'ar': ['o', 'as', '', 'amos', 'ais', 'an'], 'er': ['o', 'es', '', 'emos', 'eis', 'en'], 'ir': ['o', 'es', 'e', 'imos', 'is', 'en'] } return [verb[:-2] + c if len(c) > 0 else verb[:-1] + c for c in conj[verb[-2:]]]
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Here is the simple solution in Python:
Nice answer. Here is a suggestion that gets rid of the duplicate code by putting the verb endings in a dict and using a comprehension to give the result: