0

Please figureout the problem, in this code input: 1232323 232 output: 2

https://code.sololearn.com/c0ym89ebtcwX/?ref=app

6th Jun 2020, 5:59 PM
Psycho
Psycho - avatar
6 Respuestas
+ 2
Psycho I think you copied this code from somewhere so there are some special characters added. Check this I have rewrite the code and working fine https://code.sololearn.com/cgWFzrFGmrE3/?ref=app
6th Jun 2020, 6:21 PM
A͢J
A͢J - avatar
+ 12
Looks like you copied and pasted the code and brought in some unwanted characters. I would copy and paste it into MS Word as plain text, then copy and paste it back into a blank new code in the Playground to get rid of them. You may have to tidy up the spacing and indenting to get it running properly.
6th Jun 2020, 6:15 PM
David Ashton
David Ashton - avatar
+ 7
Regardless of the fact that there are invalid characters in the code, there is a much simpler way to do this task. text = 'This is not a list' sub = 'is' print(text.count(sub)) # or in a nice formatting: print(f'substring: "{sub}" appears {text.count(sub)} times in "{text}"')
6th Jun 2020, 6:42 PM
Lothar
Lothar - avatar
+ 2
David Ashton Or copy to Notepad then directly to your destination, no need for the extra "paste as plain text" step as with MS Word.
6th Jun 2020, 6:46 PM
Kosai Al Khateb
Kosai Al Khateb - avatar
0
I wrote this code on online compiler and paste it here . I'm using mobile phone so there is no ms word.
7th Jun 2020, 5:29 PM
Psycho
Psycho - avatar
0
Input: abcbcbc bcb Output:2 Here, I'm trying to find how many times the sub string comes in the string . 1- in abcb 2 - in bcbc
7th Jun 2020, 5:37 PM
Psycho
Psycho - avatar