Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
ArshiaRx authored Aug 24, 2021
1 parent 0889108 commit 75689a8
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions String-2/cat_dog.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#CodingBat - Python

#cat_dog

#Return True if the string "cat" and "dog" appear the same number of times in
#the given string.

# cat_dog('catdog') → True
# cat_dog('catcat') → False
# cat_dog('1cat1cadodog') → True

def cat_dog(str):
count1, count2 = 0, 0

for e in range(len(str)):
if str[e:e+3] == "cat":
count1 += 1
elif str[e:e+3] == "dog":
count2 += 1

if count1 == count2:
return True
return False


print(cat_dog('catdog'))
print(cat_dog('catcat'))
print(cat_dog('1cat1cadodog'))

0 comments on commit 75689a8

Please sign in to comment.