Skip to content

Instantly share code, notes, and snippets.

@mayankdawar
Created February 19, 2020 17:54
Show Gist options
  • Save mayankdawar/ffbe007ca4344cda8133e32069df42ba to your computer and use it in GitHub Desktop.
Save mayankdawar/ffbe007ca4344cda8133e32069df42ba to your computer and use it in GitHub Desktop.
Challenge For each word in words, add ‘d’ to the end of the word if the word ends in “e” to make it past tense. Otherwise, add ‘ed’ to make it past tense. Save these past tense words to a list called past_tense.
words = ["adopt", "bake", "beam", "confide", "grill", "plant", "time", "wave", "wish"]
past_tense = []
for i in words:
if(i[len(i)-1] == 'e'):
i += 'd'
else:
i += 'ed'
past_tense.append(i)
@swarba015
Copy link

Hi!. I realized adding little bit of explanation will help new coder's to understand the code better. :)

words = ["adopt", "bake", "beam", "confide", "grill", "plant", "time", "wave", "wish"]

//creating an empty list named "past_tense"
past_tense = []

for i in words:
if i[-1] == "e": // i[-1] indicates the last element of the i's
i = i+ "d"
past_tense.append(i) // The append() method adds an item to the end of the list.
else:
i = i + "ed"
past_tense.append(i)
print(past_tense)

@ProfDavidSerrano
Copy link

words = ["adopt", "bake", "beam", "confide", "grill", "plant", "time", "wave", "wish"]
past_tense=[]
for i in words:
if i[-1]=="e":
past_tense.append(i+"d")
else:
past_tense.append(i+"ed")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment