Assignment:
Return the number of occurrences of character c in string s,
ignoring case. Use loops. Do not use the in-built string method count,
which does a similar thing. The idea is to learn to write loops. You
should ignore case when comparing a character of s with c.
My attempt:
def countletter(s, c): #BAD
count = 0
for c in s:
if c == c:
count += 1
return count
Am I on the right track? I seem to get some assertion errors when I test it in the main…
your
returnis at wrong place. So your function is actually returning only after one iteration.Also you should not use the variable name
cin for loop, use some different variable, as it replaces the value ofcrecieved from the function call with the current character being fetched by thefor-loop.