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

my_replace

def setup():
   string = 'thailand'
   replace = 'good'
   print(string, "New", my_replace(string, replace))
   assert my_replace(string, replace) == 'goodland'

def my_replace(string, replace):
   new = ''
   i = 0
   while (i < len(string)):
      if (i < len(replace)):
         new = new + replace[i]
      elif (i >= len(replace)):
         new = new + string[i]
      i = i+1
   return new

setup()

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

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