count_code¶
Requirements:
substrings and slicing
if, else
loop through a string (while)
loop with an accumulator variable
Output the number of times that the string “code” appears anywhere in the inputted string, except we’ll accept any letter for the 'd'
, so "cope"
and "cooe"
count.
This exercise was taken from codingbat.com and has been adapted for the Python language. There are many great programming exercises there, but the majority are created for Java.