วันอาทิตย์ที่ 4 ตุลาคม พ.ศ. 2558

Lab 5 - (Function) my_endswith()

def my_endswith(word,check):
   i = len(word)-len(check)
   a = 0
   if(len(word)>=len(check)):
      while(i<len(word)):
         if(word[i] == check[a]):
            i = i + 1
            a = a + 1
         else:
            return False
      return True

my_endswith("thailand","land")
assert my_endswith("thailand","land")
assert my_endswith("thailand","thai") == False



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

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