i = 0
numAlpha = 0
while(i<len(string)):
if(string[i] == alphabet):
numAlpha+=1
i+=1
return numAlpha
def setup():
S = 'Straightforward'
alp = 'r'
assert(my_count(S,alp) == 3 )
print('number of',alp,'in',S,'is',my_count(S,alp))
setup()
Result
number of r in Straightforward is 3
ไม่มีความคิดเห็น:
แสดงความคิดเห็น