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 0d2c2ca commit c66d0f0Copy full SHA for c66d0f0
String-2/count_code.py
@@ -0,0 +1,22 @@
1
+#CodingBat - Python
2
+
3
+#count_code
4
5
+#Return the number of times that the string "code" appears anywhere in the given
6
+#string, except we'll accept any letter for the 'd', so "cope" and "cooe" count.
7
8
+# count_code('aaacodebbb') → 1
9
+# count_code('codexxcode') → 2
10
+# count_code('cozexxcope') → 2
11
12
+def count_code(str):
13
+ count = 0
14
+ for e in range( len(str) - 3 ):
15
+ if str[e:e+2] == "co" and str[e+3] == "e":
16
+ count += 1
17
+ return count
18
19
20
+print(count_code('aaacodebbb'))
21
+print(count_code('codexxcode'))
22
+print(count_code('cozexxcope'))
0 commit comments