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 25, 2021
1 parent 0d2c2ca commit c66d0f0
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions String-2/count_code.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#CodingBat - Python

#count_code

#Return the number of times that the string "code" appears anywhere in the given
#string, except we'll accept any letter for the 'd', so "cope" and "cooe" count.

# count_code('aaacodebbb') → 1
# count_code('codexxcode') → 2
# count_code('cozexxcope') → 2

def count_code(str):
count = 0
for e in range( len(str) - 3 ):
if str[e:e+2] == "co" and str[e+3] == "e":
count += 1
return count


print(count_code('aaacodebbb'))
print(count_code('codexxcode'))
print(count_code('cozexxcope'))

0 comments on commit c66d0f0

Please sign in to comment.