วันอังคารที่ 29 กันยายน พ.ศ. 2558

LAB 5 my_startwith my_endwith

def setup():
   array = "overloader    Over"
   assert (my_startwith(array,"over"))
   print ("boolean of start with is",my_startwith(array,"over"))
   assert (my_endwith(array,"er"))
   print ("boolean of end with is",my_endwith(array,"er"))

def my_startwith(array,startWith):
   if(len(array)>=len(startWith)):
      i=0
      while(i<len(startWith)):
         if(array[i]==startWith[i]):
            i=i+1
         else:
            return False
      return True
 
def my_endwith(array,endWith):
   if(len(array)>=len(endWith)):
      i=len(array)-len(endWith)
      count = 0
      while(i<len(array)):
         if(array[i]==endWith[count]):
            i=i+1
            count=count+1
         else:
            return False
      return True
 
setup()  

ผลลัพธ์
boolean of start with is True
boolean of end with is True

ไม่มีความคิดเห็น:

แสดงความคิดเห็น