samedi 24 janvier 2015

Problem with codeacademy python exercise


Write a function called censor that takes two strings, text and word, as input. It should return the text with the word you chose replaced with asterisks.



def censor(text, word):
result = []
for i in range(len(text.split())):
if text.split()[i] == 'word':
result.append("*" * len(text.split()[i]))
else:
result.append(text.split()[i])
return " ".join(result)


censor("hey hey hey", "hey") returns "hey hey hey" instead of "* * ***". Been looking at this for half an hour and cannot understand what goes wrong. I am absolutely new to programming so any pointer ( no punt intended ) or suggestion is welcome.





Aucun commentaire:

Enregistrer un commentaire