+ 1
Why does my code only work on 3/4 cases 60.2 (Python)
The task was to remove the #'s from the input, which is a sentence, and replace them with a space. For#Example! --> For Example!. Here is my code https://code.sololearn.com/c9IZgARU2nxI/?ref=app, it only works on 3/4 cases and the 4th one is hidden so I have no feedback.
6 Answers
+ 2
Elaf
Just do
print(txt.replace("#", ' '))
Nothing else
It will replace all # with space no need to check if # exist.
+ 1
Challenge's answer is good, but if you want to know why your code is failing one test, I'm guessing that test has no "#" in the input string, which would leave the variable 'text' uninitialized in your code, so your output becomes:
```
Traceback (most recent call last):
File "file0.py", line 7, in <module>
print(text)
NameError: name 'text' is not defined
```
+ 1
đ
°đ
š (Challenge Accepted) Ah yes, I did not think of that
0
đ
°đ
š (Challenge Accepted) That solved the practice, but why did my code not complete all the cases?
0
Myk Dowling Ah I see, thank you
- 1
Elaf
What if there is no # in String?