0
Python Data Structures, 5.2 Practice question
Hi, experts! It happened again and I've been stuck at the end of Python Data Structures, 5.2 Practice, editing guide Here is the code text = "Amy has 128 dollars, while David has 54 dollars. Amy is going to the zoo. David watches soccer." old_name = input('') new_name = input('') text_new = text.replace(old_name, new_name) print(text_new.count(new_name)) print(text_new) And again - no action! Your guesses, please!
2 Respuestas
+ 1
Thank you, good coder!
You've saved my day!
0
Hi Andrei!
Your code is fair enough to pass this challenge unless variable new_name is already included in text. I mean it should return 2 instead 4 if new_name is David. That's what task description said. For that, you have to count variable old_name before replacing it in text. So, it needs to be like this
text = "Amy has 128 dollars, while David has 54 dollars. Amy is going to the zoo. David watches soccer."
old_name = input('')
new_name = input('')
print(text.count(old_name))
text_new = text.replace(old_name, new_name)
print(text_new)