CODE CHALLENGE: STRING METHODS Add Exclamation

Not sure why my function isn’t passing

Create a function named add_exclamation that has one parameter named word . This function should add exclamation points to the end of word until word is 20 characters long. If word is already at least 20 characters long, just return word .

Write your add_exclamation function here:

def add_exclamation(word):
temp = “”
if len(word) < 20:
tempList = word.split()
counter = len(tempList)
while counter < 20:
tempList.append(’!’)
counter += 1
for i in range(len(tempList)):
temp += tempList[i]
return temp
else:
return word

Uncomment these function calls to test your function:

print(add_exclamation(“Codecademy”))

should print Codecademy!!!

print(add_exclamation(“Codecademy is the best place to learn”))

should print Codecademy is the best place to learn

Ok I should have used: counter = len(word)
Not len(tempList) which only returns 1

1 Like