We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 0889108 commit 75689a8Copy full SHA for 75689a8
String-2/cat_dog.py
@@ -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