+ 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.

11th Apr 2021, 5:58 AM
Elaf
6 Respostas
+ 2
Elaf Just do print(txt.replace("#", ' ')) Nothing else It will replace all # with space no need to check if # exist.
11th Apr 2021, 6:03 AM
AÍąJ
AÍąJ - avatar
+ 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 ```
11th Apr 2021, 6:11 AM
Myk Dowling
Myk Dowling - avatar
+ 1
🅰đŸ…č (Challenge Accepted) Ah yes, I did not think of that
11th Apr 2021, 6:15 AM
Elaf
0
🅰đŸ…č (Challenge Accepted) That solved the practice, but why did my code not complete all the cases?
11th Apr 2021, 6:06 AM
Elaf
0
Myk Dowling Ah I see, thank you
11th Apr 2021, 6:15 AM
Elaf
- 1
Elaf What if there is no # in String?
11th Apr 2021, 6:08 AM
AÍąJ
AÍąJ - avatar