Skip to content

Commit 75689a8

Browse files
authored
Add files via upload
1 parent 0889108 commit 75689a8

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

String-2/cat_dog.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#CodingBat - Python
2+
3+
#cat_dog
4+
5+
#Return True if the string "cat" and "dog" appear the same number of times in
6+
#the given string.
7+
8+
# cat_dog('catdog') → True
9+
# cat_dog('catcat') → False
10+
# cat_dog('1cat1cadodog') → True
11+
12+
def cat_dog(str):
13+
count1, count2 = 0, 0
14+
15+
for e in range(len(str)):
16+
if str[e:e+3] == "cat":
17+
count1 += 1
18+
elif str[e:e+3] == "dog":
19+
count2 += 1
20+
21+
if count1 == count2:
22+
return True
23+
return False
24+
25+
26+
print(cat_dog('catdog'))
27+
print(cat_dog('catcat'))
28+
print(cat_dog('1cat1cadodog'))

0 commit comments

Comments
 (0)