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!

13th Nov 2021, 8:47 PM
Andrei Shanko
Andrei Shanko - avatar
2 Answers
+ 1
Thank you, good coder! You've saved my day!
14th Nov 2021, 12:36 PM
Andrei Shanko
Andrei Shanko - avatar
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)
14th Nov 2021, 5:49 AM
Python Learner
Python Learner - avatar