Python Forum
Thread Rating:
  • 3 Vote(s) - 3.33 Average
  • 1
  • 2
  • 3
  • 4
  • 5
simple problem
#1
hey guys I've got a simple problem but it's so frustrating
I am trying to write a code to print all "bob" in this string and print the count at the end .

s = 'bobazcebobgghabobkl'
count = 0
for i in s :
    y = s.find(i)
    if i == "b":
        count = count + 1 
        print(s[y :y + 3])
print(count)
and i except to get an output:
Output:
bob bob bob 3


but I already got:
Output:
bob bob bob bob bob bob 6


what's the wrong in my simple code
Reply
#2
this question has been answered previously. use search for bob
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  A simple problem, how best to solve it? SuchUmami 2 718 Sep-01-2023, 05:36 AM
Last Post: Pedroski55
  How to solve this simple problem? Check if cvs first element is the same in each row? thesquid 2 1,224 Jun-14-2022, 08:35 PM
Last Post: thesquid
Big Grin question about simple algorithm to my problem jamie_01 1 1,669 Oct-04-2021, 11:55 AM
Last Post: deanhystad
  simple login problem MMOToaster 2 2,400 Feb-25-2020, 09:28 AM
Last Post: MMOToaster
  Problem with simple 3D Vektor calculation Pythocodras 0 1,708 Dec-11-2019, 07:18 PM
Last Post: Pythocodras
  Simple problem. looking for an efficient way silverchicken24 3 2,324 Oct-14-2019, 07:13 PM
Last Post: Larz60+
  simple string & input problem kungshamji 5 3,648 Jun-23-2019, 03:54 PM
Last Post: kungshamji
  Array - Problem with Simple Code emerger 8 4,400 Oct-12-2018, 02:46 AM
Last Post: ichabod801
  Having a problem with simple code Jotap 1 2,604 Jul-09-2018, 04:32 PM
Last Post: buran
  problem with simple class code diegoraffo 5 3,673 Jan-27-2018, 02:31 AM
Last Post: ka06059

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020