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

LAB 5 my_count my_find

def setup():
   array = "overloader"
   print ("value =",my_count(array,"e"))
   assert (my_count(array,"e")==2)
 
   print ("you fist index e is",my_find(array,"e"))
   assert (my_find(array,"e")==2)

def my_count(array,wantCount):
      i = 0
      count =0
      while(i < len(array)):
         if(array[i]==wantCount):
            count=count+1
         i=i+1
      return count
 
 
def my_find(array,wantFind):
   i = 0
   while(i<=len(array)):
      if(array[i] == wantFind):
         return i
      i=i+1
   return "."

   
 
   

setup()  


ผลลัพธ์
value = 2
you fist index e is 2

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

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