0

if I have a random string A, How can I write a Python code that will output the number of times 'pop' appears in A?

For example if A='vghedfgegopopopaeegdopopopgvepopopop', then the resulting code should output "The number of times pop appears is 7". picture of my code / and I got the wrong answer. I am expecting the occurrence to be 10, not 16.

Can you hint at what I did incorrectly?

Thanks

  • A picture of your code is not helpful, can you copy/paste it into your question? – G_M Feb 15 '18 at 01:31
  • @jsbueno That is not a duplicate as the accepted answer doesn't account for overlapping substrings (as is the case in this question). – G_M Feb 15 '18 at 01:35
  • Welcome to stackoverflow - when asking, your code should be pasted as text, and formatted with the ` { } ` button. The question was closed because it was equal or similar to the one linked too. Your code however have more problems than that - try putting a `print(char)` statement inside your loop so you can start understanding better the nature of loops. – jsbueno Feb 15 '18 at 01:37
  • There are answers there that do account for overlapping substrings. – jsbueno Feb 15 '18 at 01:37

0 Answers0