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

Lab5-My find

def my_find(string,alphabet):
   i = 0
   posAlpha = 0
   print('position of',alphabet,'in',string,'is')
   while(i<len(string)):
      if(string[i] == alphabet):
         print(i)
      i+=1

def setup():
   S = 'Straightforward'
   alp = 'r'
   my_find(S,alp)
setup()  

Result
position of r in Straightforward is
2
10
13

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

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