Function Detective
Sign in to Google to save your progress. Learn more
The questions below are based on the Python program below and its output. You haven't seen some of these Python statements and constructs before, we're hoping you can reason about them from the code and the program output
Input file is words.txt:
phone
book
baby
punch
fox
elf
country
sun

Code here:

def pluralize(word):
    ret = word + "s"
    if word.endswith("ch"):
        ret = word + "es"
    if word.endswith("x"):
        ret = word + "es"
    if word.endswith("f"):
        ret = word[:-1] + "ves"
    if word.endswith("y"):
        ret = word[:-1] + "ies"
    return ret
       
if __name__ == "__main__":
    f = open("words.txt")
    for w in f:
        w = w.strip()  
        print w, pluralize(w)

output here

phone phones
book books
baby babies
punch punches
fox foxes
elf elves
country countries
sun suns
Based on the output for the word "elf" and "country", which do you think is the best explanation of the python operator [:-1] when it's applied to a string? *
Which of the following is the best explanation for the code 'for w in f:'
this code is in the 'main' program block
Clear selection
Enter a word for which you think function pluralize will return an incorrect plural *
Which of the following is the best explanation for the first statement in function pluralize: *
 ret = word + "s"
Name(s) comma separated, first and last *
netid *
netid (partner, optional)
netid (partner, optional)
netid (partner, optional)
Submit
Clear form
Never submit passwords through Google Forms.
This content is neither created nor endorsed by Google. Report Abuse - Terms of Service - Privacy Policy