Site Loader
111 Rock Street, San Francisco

Hi, I guess this is not the best practice but it works 🙂

Let’s count “cat” in a given string.

mystery_string = "why cat wy dog cat cacacat cacacat o cat bye cat cat"
uzunluk_my_string = len(mystery_string)
cat_sayisi = 0
for i in range(0,uzunluk_my_string):
    if mystery_string[i] == "c":
        #print(i," ",mystery_string[i])
        if mystery_string[i+1] == "a":
            if mystery_string[i+2] == "t":
                cat_sayisi = cat_sayisi + 1


# The output is 7

Post Author:

Leave a Reply

Your email address will not be published. Required fields are marked *