วันอังคารที่ 27 ตุลาคม พ.ศ. 2558

LAB 7 replace

def setup():
   set_string = string("A","B","C")
   set_string.display()
   set_string.replace("0","+")
   set_string.display()
   set_string.replace("7","0")
   set_string.display()
   set_string.replace("-","7")
   set_string.display()
   set_string.replace("*","-")
   set_string.display()

   
class string():
   def __init__(self,char1,char2,char3):
      self.char1 =find_row_string(char1)
      self.char2 =find_row_string(char3)
      self.char3 =find_row_string(char3)
 
   def display(self):
      count = 0
      while(count<len(self.char1)):
         print(self.char1[count],self.char2[count],self.char3[count])
         count +=1
 
   def replace(self,replace,getout):
      count_row = 0
      while(count_row<len(self.char1)):
         count_string =0
         self.char1[count_row] = my_replace(self.char1[count_row],getout,replace)
         self.char2[count_row] = my_replace(self.char2[count_row],getout,replace)
         self.char3[count_row] = my_replace(self.char3[count_row],getout,replace)
         count_row +=1
       
   
def my_replace(string,getout,replace):
   result = ""
   i = 0
   while( i < len(string) ):
      if(string[i] == getout):
         result = result + replace
         i = i +len(replace)
      else:
         result = result + string[i]
         i = i +1
   return result  

   
def find_row_string(data):
   count = 0
   result =[]
   while(count<len(data)):
      result +=find_row_char(data[count])
      count  += 1
   return result
 
def find_row_char(data):
   result = []
   result = setKey(data)
   return result
 
def setKey(key):
   row_1_A = "    +    "
   row_2_A = "   + +   "
   row_3_A = "  +   +  "
   row_4_A = " +  +  + "
   row_5_A = "+       +"
   key_A   = [row_1_A,row_2_A,row_3_A,row_4_A,row_5_A]
   row_1_E = "++++++++"
   row_2_E = "++      "
   row_3_E = "++++++++"
   row_4_E = "++      "
   row_5_E = "++++++++"
   key_E   = [row_1_E,row_2_E,row_3_E,row_4_E,row_5_E]
   row_1_C = " +++++++"
   row_2_C = "+++     "
   row_3_C = "++      "
   row_4_C = "+++     "
   row_5_C = " +++++++"
   key_C   = [row_1_C,row_2_C,row_3_C,row_4_C,row_5_C]
   row_1_B = "+++++++ "
   row_2_B = "+      +"
   row_3_B = "+++++++ "
   row_4_B = "+      +"
   row_5_B = "+++++++ "
   key_B   = [row_1_B,row_2_B,row_3_B,row_4_B,row_5_B]
   if(key == 'A'):
      return key_A
   elif(key == 'B'):
      return key_B
   elif(key == 'C'):
      return key_C
   elif(key == 'E'):
      return key_E
   else:
     return ["","","","",""]

setup()
    +      +++++++  +++++++
   + +    +++      +++     
  +   +   ++       ++      
 +  +  +  +++      +++     
+       +  +++++++  +++++++
    0      0000000  0000000
   0 0    000      000     
  0   0   00       00      
 0  0  0  000      000     
0       0  0000000  0000000
    7      7777777  7777777
   7 7    777      777     
  7   7   77       77      
 7  7  7  777      777     
7       7  7777777  7777777
    -      -------  -------
   - -    ---      ---     
  -   -   --       --      
 -  -  -  ---      ---     
-       -  -------  -------
    *      *******  *******
   * *    ***      ***     
  *   *   **       **      
 *  *  *  ***      ***     
*       *  *******  *******

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

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