Skip to content

Commit c66d0f0

Browse files
authored
Add files via upload
1 parent 0d2c2ca commit c66d0f0

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

String-2/count_code.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)