Sunday, October 4, 2015

Lab5 - my_startswith() e.g. my_startswith("Thailand", "Sun") -> return False

def setup():

    input_string = "Thailand"

    reference = "Sun"

    assert my_startswith(input_string,reference) ==input_string.startswith(reference)

    print(my_startswith(input_string,reference))

 

def my_startswith(string,reference):

    index = 0

    startswith = True
   
    while(index < len(string)and startswith):

        if(string[index] == reference[index]):

            index+=1
       
            startswith = True
       
        else:
           
            startswith = False
           
    return startswith

setup()

No comments:

Post a Comment