-ing It!
Please Log In for full access to the web site.
Note that this link will take you to an external site (https://shimmer.mit.edu) to authenticate, and then you will be redirected back to this page.
As an intern at New Active Systems Auto-correct (NASA) you have been assigned the exciting task of adding 'ing'
to all of the strings in a list of strings. Given the starter file below, complete the functions in the file according to the descriptions in the comments.
Notes:
- challenge_verbing is actually a challenge! It's ok if you need help or don't find a complete solution. Hint: How can you count the number of trailing e's in a string when you don't know how many there are? Should you start at the beginning or the end of a word to count the trailing e's?
def verbing(words):
"""
Inputs:
words (list<str>) - list of words
Returns:
A new list of strings resulting from adding 'ing' to the end of each
word. Ex: ["ease", "flee"] -> ["easeing", "fleeing"]
"""
pass # your code here
def better_verbing(words):
"""
Inputs:
words (list<str>) - list of words
Returns:
A new list of strings resulting from adding 'ing' to the end of each
string. Cut off the trailing 'e's of words that have them, before
adding 'ing'. If there are multiple trailing 'e's, just cut off the
last one. Ex: ["ease", "flee"] -> ["easing", "fleing"]
"""
pass # your code here
def challenge_verbing(words):
"""
Inputs:
words (list<str>) - list of words
Returns:
A new list of strings resulting from adding 'ing' to the end of each
string. Cut off all the trailing 'e's of words that have them, before
adding 'ing'. Ex: ["ease", "flee"] -> ["easing", "fling"]
"""
pass # your code here
if __name__ == "__main__":
# Local testing -- feel free to add your own tests as well!
# "\n" is the new line character, "\t" is the tab character
words = ["eat", "sleep", "code", "appointee"]
print(f"Got {verbing(words)=}\n\t Expected=['eating', 'sleeping', 'codeing', 'appointeeing']")
print(f"Got {better_verbing(words)=}\n\t\t Expected=['eating', 'sleeping', 'coding', 'appointeing']")
print(f"Got {challenge_verbing(words)=}\n\t\t Expected=['eating', 'sleeping', 'coding', 'appointing']")
No file selected
Next Exercise: A Slice of Pi