Monday, September 28, 2015

Lab5 - my_count() e.g. my_count("Thailand", "a") -> return 2

def setup():
    input_string = "Thailand"
    reference = "a"
    count_string = my_count(input_string,reference)
    print(count_string)
   
def my_count(string,reference):
    index = 0
    count = 0
    while(index < len(string)):
        if(string[index] == reference):
            count+=1
        index+=1
    return count

setup()

No comments:

Post a Comment