- #1
ver_mathstats
- 260
- 21
- Homework Statement
- Return the number of times that the string "code" appears anywhere in a given string
- Relevant Equations
- Using python
Python:
def count_code(str):
count = 0
for c in range(len(str)-1):
if str[c] == 'c' and str[c+1] == 'o' and str[c+2] == 'd' and str[c+3] == 'e':
count+=1
return count
Any help would be greatly appreciated. Thank you.
<mentor add code tags>
Last edited by a moderator: