Solution: HW04
testfuncscerrsol_stdoutsol_keptsol_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_21.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display1.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 678, 'const': 678, 'code+const': 1356}
# HW4_String_File_Processing (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)
# - เขียนในเซลล์นี้เท่านั้น 
# - ถ้าต้องการเขียนฟังก์ชันเพิ่ม ก็เขียนในเซลล์นี้
# ตัวแปรต่อไปนี้เป็นตัวแปรที่กำหนดค่าสีเพื่อเอาไว้ใช้ในโปรแกรม (ห้ามแก้ไข)
RESET = '\033[0m'
RED = '\033[;31m'
GREEN = '\033[;32m'
BLUE = '\033[;34m'
HIGHLIGHT = '\033[;103m'
# ---------------------------------------------------
def red(s):
    return RED + s + RESET
# ---------------------------------------------------
def green(s):
    return GREEN + s + RESET
# ---------------------------------------------------
def blue(s):
    return BLUE + s + RESET
# ---------------------------------------------------
def highlight(s):
    return HIGHLIGHT + s + RESET
# ---------------------------------------------------
def color_text(s, color):
    color = color.lower()
    if color == 'red':
        return red(s)
    elif color == 'green':
        return green(s)
    elif color == 'blue':
        return blue(s)
    return s
# ---------------------------------------------------
def color_tag(s):
    k = s.find('>')
    return color_text(s[k+1:-3], s[1:k])
# ---------------------------------------------------
def highlight_words(s, words):
    for w in words:
        s = s.replace(w, highlight(w))
    return s
def highlight_words(s, words):
    for w in words:
        S = s.upper()
        w = w.upper()
        k0 = 0
        k1 = S.find(w)
        out = ''
        while k1 >= 0:
            out += s[k0:k1] + highlight(s[k1:k1+len(w)])
            k0 = k1 + len(w)
            k1 = S.find(w, k0)
        s = out + s[k0:]
    return s
# ---------------------------------------------------
def colorize(t, tag):
    out = ''
    k0 = 0
    k1 = t.find(tag)
    while k1 >= 0:
        k2 = t.find('</>', k1)
        out += t[k0:k1] + color_text(t[k1+len(tag):k2], tag[1:-1])
        k0 = k2+3
        k1 = t.find(tag, k0)
    return out + t[k0:]
def display_tag_file(filename):
    f = open(filename, encoding='utf-8')
    for line in f:
        line = line.rstrip()
        line = colorize(line, '<red>')
        line = colorize(line, '<green>')
        line = colorize(line, '<blue>')
        print(line)
    f.close()

Testsuite: HW04
from spj_grader import *
import builtins
import random

class Testsuite(spjTestsuite):

    datafiles = {'song.txt':
                 'abc<red>rrr</>pkk\n' +
                 'def<green>ggg</>ocr\n' +
                 'xyz<blue>bbb</>abc\n' +
                 'abc<red>rrr</>pf<green>ggg</>o<red>rr</>z<blue>bbb</>abc'}

    @spjTestsuite.testcase(spjTestsuite.score_exact_kept)
    def test_highlight_1(self):
        global RESET, RED, GREEN, BLUE, HIGHLIGHT
        RESET = '\033[0m'
        RED = '\033[;31m'
        GREEN = '\033[;32m'
        BLUE = '\033[;34m'
        HIGHLIGHT = '\033[;103m'        
        self.keep(highlight_words('abcdefgabcabbcbffgcdabcaaabc',
                                  ['abc', 'fg']))

    @spjTestsuite.testcase(spjTestsuite.score_exact_kept)
    def test_highlight_2(self):
        global RESET, RED, GREEN, BLUE, HIGHLIGHT
        RESET = '\033[0m'
        RED = '\033[;31m'
        GREEN = '\033[;32m'
        BLUE = '\033[;34m'
        HIGHLIGHT = '\033[;103m'        
        self.keep(highlight_words('aBCdefgAbcAbbcbffGcdabcaaabc',
                                  ['abc', 'fg']))

    @spjTestsuite.testcase(spjTestsuite.score_exact_stdout,
                           files = datafiles,)
    def test_display(self):
        global RESET, RED, GREEN, BLUE, HIGHLIGHT
        RESET = '\033[0m'
        RED = '\033[;31m'
        GREEN = '\033[;32m'
        BLUE = '\033[;34m'
        HIGHLIGHT = '\033[;103m'        
        display_tag_file('song.txt')

6130394021: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_10.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0mc']
test_highlight_20.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0mc']
test_display0.0
abcrrrpkk

defgggocr

xyzbbbabc

abcrrrpf<green>ggg</>o<red>rr</>z<blue>bbb</>abc
abc<red>rrr</>pf<green>ggg</>o<red>rr</>z<blue>bbb</>abc
[]
bytecount: {'code': 860, 'const': 553, 'code+const': 1413}
def red(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return RED+str(s)+RESET
# ---------------------------------------------------
def green(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return GREEN+str(s)+RESET
# ---------------------------------------------------
def blue(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return BLUE+str(s)+RESET
# ---------------------------------------------------
def highlight(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return HIGHLIGHT+str(s)+RESET
# ---------------------------------------------------
def color_text(s, color):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    x = color.lower()
    if x == "red":
        return red(s)
    elif x == "green":
        return green(s)
    elif x == "blue":
        return blue(s)
    else:
        return s
# ---------------------------------------------------
def color_tag(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    a = s.find(">")
    b = s.find("<", a)
    if a == 4:
        return red(s[a+1:b])
    elif a == 6:
        return green(s[a+1:b])
    else:
        return blue(s[a+1:b])
# ---------------------------------------------------
def highlight_words(s, words):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    if words == []:
        return s
    x = s+"Phakin"
    counts = 0
    result = []
    for i in range(len(x)-len(words[0])):
        if x[i:i+len(words[0])] == words[0]:
            counts += 1
    a = s.find(words[0])
    result.append(s[:a])
    for i in range(counts):
        hi = highlight(s[a:a+len(words[0])])
        result.append(hi)
        j = a+len(words[0])
        a = s.find(words[0], j)
        result.append(s[j:a])
    result.append(s[-1])
    return "".join(result)
# ---------------------------------------------------
def display_tag_file(filename):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    fn = open(filename, 'r', encoding='utf-8')
    for line in fn:
      x = line.find("<")
      y = line.find(">")
      a = line.find(">")
      b = line.find("<", a)
      if y-x == 4:
        print(line[:x]+red(line[a+1:b])+line[b+3:])
      if y-x == 5:
        print(line[:x]+blue(line[a+1:b])+line[b+3:])
      if y-x == 6:
        print(line[:x]+green(line[a+1:b])+line[b+3:])
    print(line)
    fn.close()

6230003221: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_21.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display1.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 484, 'const': 413, 'code+const': 897}
def red(s):
    return RED+s+RESET
# ---------------------------------------------------
def green(s):
    return GREEN+s+RESET
# ---------------------------------------------------
def blue(s):
    return BLUE+s+RESET
# ---------------------------------------------------
def highlight(s):
    return HIGHLIGHT+s+RESET
# ---------------------------------------------------
def color_text(s, color):
    if color.lower() =="red":
        return red(s)
    if color.lower() =="green":
        return green(s)
    if color.lower() =="blue":
        return blue(s)
    else:
        return s
# ---------------------------------------------------
def color_tag(s):
    s=s.replace("<red>",RED)
    s=s.replace("<green>",GREEN)
    s=s.replace("<blue>",BLUE)
    s=s.replace("</>",RESET)
    return s
# ---------------------------------------------------
def highlight_words(s, words):
    k=s.upper()
    out=""
    for i in range(len(words)):
        p=0
        while True:
            f=k[p:].find(words[i].upper())
            if f != -1 :
                out+=s[p:f+p]+highlight(s[f+p:f+p+len(words[i])])
                p=f+len(words[i])+p
            else:
                break
        out+=s[p:]
        s=out
        k=s.upper()
        out=""
    return s
# ---------------------------------------------------
def display_tag_file(filename):
    f=open(filename,"r",encoding="utf-8")
    text=f.read()
    f.close()
    print(color_tag(text))

6230046221: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_21.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display1.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 590, 'const': 495, 'code+const': 1085}
def red(s):
    return RED+s+RESET
# ---------------------------------------------------
def green(s):
    return GREEN+s+RESET
# ---------------------------------------------------
def blue(s):
    return BLUE+s+RESET
# ---------------------------------------------------
def highlight(s):
    return HIGHLIGHT+s+RESET
# ---------------------------------------------------
def color_text(s, color):
    color = color.lower()
    if color == 'red':
        return red(s)
    elif color == 'green':
        return green(s)
    elif color == 'blue':
        return blue(s)
    return s
# ---------------------------------------------------
def color_tag(s):
    i = s.index('>')
    j = s.index('</>')
    return color_text(s[i+1:j], s[1:i])
# ---------------------------------------------------
def highlight_words(s, words):
    cs = s.lower()
    process = []
    for word in words:
        word = word.lower()
        len_word = len(word)
        i = x = 0
        while True:
            i = cs.find(word,x)
            if i == -1: break
            x = i + len_word
            process.append([i,x])
    process.sort()
    out = ''
    p = 0
    for prop in process:
        out += s[p:prop[0]] + highlight(s[prop[0]:prop[1]])
        p = prop[1]
    out += s[p:]
    return(out)
# ---------------------------------------------------
def display_tag_file(filename):
    f = open(filename, 'r', encoding='utf-8')
    fs = f.read().strip()
    f.close()
    i = j = x = 0
    out = ''
    while True:
        i = fs.find('<', x)
        j = fs.find('</>', x) + 3
        if i == -1: break
        out += (fs[x:i] + color_tag(fs[i:j]))
        x = j
    out += fs[x:]
    print(out)

6230058821: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display0.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 412, 'const': 505, 'code+const': 917}
def red(s):
    return "\033[;31m" + s + "\033[0m"
# ---------------------------------------------------
def green(s):
    return "\033[;32m" + s + "\033[0m"
# ---------------------------------------------------
def blue(s):
    return "\033[;34m" + s + "\033[0m"
# ---------------------------------------------------
def highlight(s):
    return "\033[;103m" + s + "\033[0m"
# ---------------------------------------------------
def color_text(s, color):
    if color.lower() == "red":
        return red(s)
    elif color.lower() == "green":
        return green(s)
    elif color.lower() == "blue":
        return blue(s)
    else:
        return s
# ---------------------------------------------------
def color_tag(s):
    a = s[1:-3].split(">")
    return color_text(a[1],a[0])
# ---------------------------------------------------
def highlight_words(s, words):
    s_new = ""
    if len(words) == 0:
      return s
    else:
      for i in words:
        if i == words[0]:
          a = s.split(i)
          for e in a:
            s_new += e + highlight(i)
          s_new = s_new[:-(len(highlight(i)))]
        else:
          a = s_new.split(i)
          s_new = ""
          for e in a:
            s_new += e + highlight(i)
          s_new = s_new[:-(len(highlight(i)))]
      return s_new
# ---------------------------------------------------
def display_tag_file(filename):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    pass

6230063921: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_21.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display1.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 670, 'const': 449, 'code+const': 1119}
def red(s):
    return RED + s + RESET
# ---------------------------------------------------
def green(s):
    return GREEN + s + RESET
# ---------------------------------------------------
def blue(s):
    return BLUE + s + RESET
# ---------------------------------------------------
def highlight(s):
    return HIGHLIGHT + s + RESET
# ---------------------------------------------------
def color_text(s, color):
    if color.lower() == 'red':
        return red(s)
    elif color.lower() == 'green':
        return green(s)
    elif color.lower() == 'blue':
        return blue(s)
    else:
        return s
# ---------------------------------------------------
def color_tag(s):
    k1 = s.find('<')
    k2 = s.find('>')
    k3 = s.find('<',k2)
    color = s[k1+1:k2]
    txt = s[k2+1:k3]
    return color_text(txt,color)
# ---------------------------------------------------
def highlight_words(s, words):
    s1 = s.lower()
    for e in words:
        e= e.lower()
        i = 0
        while i < len(s1):
            k1 = s1.find(e,i)
            if k1 >= 0:
                s = s[:k1] + highlight(s[k1:k1+len(e)]) +s[k1+len(e):]
                s1 = s1[:k1] + highlight(s1[k1:k1+len(e)]) +s1[k1+len(e):]
                i = len(s[:k1])+len(e)+ len(highlight(''))
            else:
                break                    
    return s
# ---------------------------------------------------
def display_tag_file(filename):
    f1 = open(filename, 'r', encoding='utf-8')
    s = ''
    for line in f1:
        s+= line
    f1.close()
    i = 0
    ans =''
    while i < len(s):
        if s[i] == '<':
            k1 = s.find('>',i)
            k2 = s.find('>',k1+1)
            ans += color_tag(s[i:k2+1])
            i = k2+1
        else:
            ans += s[i]
            i += 1
    print(ans)

6230065121: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display0.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 474, 'const': 931, 'code+const': 1405}
def red(s):
    RESET = '\033[0m'
    RED = '\033[;31m'
    GREEN = '\033[;32m'
    BLUE = '\033[;34m'
    HIGHLIGHT = '\033[;103m'
    s=RED+s+RESET
    return s
# ---------------------------------------------------
def green(s):
    RESET = '\033[0m'
    RED = '\033[;31m'
    GREEN = '\033[;32m'
    BLUE = '\033[;34m'
    HIGHLIGHT = '\033[;103m'
    s=GREEN+s+RESET
    return s
# ---------------------------------------------------
def blue(s):
    RESET = '\033[0m'
    RED = '\033[;31m'
    GREEN = '\033[;32m'
    BLUE = '\033[;34m'
    HIGHLIGHT = '\033[;103m'
    s=BLUE+s+RESET
    return s
# ---------------------------------------------------
def highlight(s):
    RESET = '\033[0m'
    RED = '\033[;31m'
    GREEN = '\033[;32m'
    BLUE = '\033[;34m'
    HIGHLIGHT = '\033[;103m'
    s=HIGHLIGHT+s+RESET
    return s
# ---------------------------------------------------
def color_text(s, color):
    if color.upper()=="RED":
        s=red(s)
    if color.upper()=="GREEN":
        s=green(s)
    if color.upper()=="GREEN":
        s=blue(s)
    return s
# ---------------------------------------------------
def color_tag(s):
    k=s.split(">")
    k[0]=k[0][1::]
    k[1]=k[1][:-2:]
    if k[0]=="red":
        j=red(k[1])
    if k[0]=="green":
        j=green(k[1])
    if k[0]=="blue":
        j=red(k[1])
    if k[0] not in ["red","blue","green"]:
        j=s
    return j
# ---------------------------------------------------
def highlight_words(s, words):
    for e in words:
        g=highlight(e)
        s=s.replace(e,g)
    return s
# ---------------------------------------------------
def display_tag_file(filename):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    pass

6230071921: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_21.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display1.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 830, 'const': 1404, 'code+const': 2234}
def red(s):
    a=''
    for i in s:
        a+=('\033[;31m'+i+'\033[0m')
    return a
# ---------------------------------------------------
def green(s):
    b=''
    for i in s:
        b+=('\033[;32m'+i+'\033[0m')
    return b
# ---------------------------------------------------
def blue(s):
    c=''
    for i in s:
        c+=('\033[;34m'+i+'\033[0m')
    return c
# ---------------------------------------------------
def highlight(s):
    d=''
    for i in s:
        d+=('\033[;103m'+i+'\033[0m')
    return d
# ---------------------------------------------------
def color_text(s, color):
    e=''
    if color.lower() == 'red':
            e+='\033[;31m'+s+'\033[0m'
            return e
    elif color.lower() == 'green':
            e+='\033[;32m'+s+'\033[0m'
            return e
    elif color.lower() == 'blue':
            e+='\033[;34m'+s+'\033[0m'
            return e
    else:
        return s
# ---------------------------------------------------
def color_tag(s):
    g=''
    for i in range(len(s)):
        if s[0:5:1]=='<red>':
            g+='\033[;31m'+s[5:-3:1]+'\033[0m'
            return g
        elif s[0:7:1]=='<green>':
            g+='\033[;32m'+s[7:-3:1]+'\033[0m'
            return g
        elif s[0:6:1]=='<blue>':
            g+='\033[;34m'+s[6:-3:1]+'\033[0m'
            return g
# ---------------------------------------------------
def highlight_words(s, words):
    h=[]
    ss = s.upper()
    run = True
    ans =''
    c=0
    for i in words:
        aa=len(i)
        k=0;j=0
        i=i.upper()
        while run:
            k = ss.find(i,j)
            if k == -1:
                break
            j = aa+k
            h.append([k,j])
    h.sort()
    for m in h :
        ans+= s[c:m[0]] + '\033[;103m'+s[m[0]:m[1]]+'\033[0m'; c=m[1]
    ans+= s[c::]     
    return ans
# ---------------------------------------------------
def red2(s):
    return s.replace('<red>', RED).replace('</>', RESET)
def green2(s):
    return s.replace('<green>', GREEN).replace('</>', RESET)
def blue2(s):
    return s.replace('<blue>', BLUE).replace('</>', RESET)
# ---------------------------------------------------
def display_tag_file(filename):
    file = open(filename, 'r', encoding='utf-8')
    print(blue2(green2(red2(file.read()))))

6230083421: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display1.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 542, 'const': 1193, 'code+const': 1735}
def red(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return '\033[;31m'+s+'\033[0m'
# ---------------------------------------------------
def green(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return '\033[;32m'+s+'\033[0m'
# ---------------------------------------------------
def blue(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return '\033[;34m'+s+'\033[0m'
# ---------------------------------------------------
def highlight(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return '\033[;103m'+s+'\033[0m'
# ---------------------------------------------------
def color_text(s, color):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    if color.lower() == 'red':
      return '\033[;31m'+s+'\033[0m'
    elif color.lower() == 'green':
      return '\033[;32m'+s+'\033[0m'
    elif color.lower() == 'blue':
      return '\033[;34m'+s+'\033[0m'
    else :
      return s
# ---------------------------------------------------
def color_tag(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    a = s.find('>')
    b = s.find('<',1)
    if s[1:a].lower() == 'red':
      return '\033[;31m'+s[a+1:b]+'\033[0m'
    elif s[1:a].lower() == 'green':
      return '\033[;32m'+s[a+1:b]+'\033[0m'
    elif s[1:a].lower() == 'blue':
      return '\033[;34m'+s[a+1:b]+'\033[0m'
# ---------------------------------------------------
def highlight_words(t, w):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    out = [t]
    if len(w) != 0:
        for i in range(len(w)):
            if w[i] in t:
                ch = w[i]
                out.append(out[i].replace(ch,'\033[;103m'+ch+'\033[0m'))
    else :
        out.append(t)
    return out[len(w)]
# ---------------------------------------------------
def display_tag_file(filename):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    f = open(filename, 'r', encoding='utf-8')
    txt = f.read()
    f.close()
    out = txt.replace('<red>','\033[;31m').replace('</>','\033[0m').replace('<green>','\033[;32m').replace('<blue>','\033[;34m')
    print(out)

6230089221: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display0.0
abcrrrpkk

defgggocr

xyzbbbabc

abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 492, 'const': 885, 'code+const': 1377}
def red(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    p="\033[;31m"+s+"\033[0m"
    return p
# ---------------------------------------------------
def green(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    p="\033[;32m"+s+"\033[0m"
    return p
# ---------------------------------------------------
def blue(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    p="\033[;34m"+s+"\033[0m"
    return p
# ---------------------------------------------------
def highlight(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    p="\033[;103m"+s+"\033[0m"
    return p
# ---------------------------------------------------
def color_text(s, color):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    if color.lower()=="red":
      q=red(s)
    elif color.lower()=="green":
      q=green(s)
    elif color.lower()=="blue":
      q=blue(s)
    else:
      q=s
    return q
# ---------------------------------------------------
def color_tag(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    s=s[1:-3:]
    s=s.split(">")
    q=color_text(s[1],s[0])
    return q
# ---------------------------------------------------
def highlight_words(s, words):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    if len(words)!=0:
        for i in range(len(words)):
            s=s.split(words[i])
            z=highlight(words[i])
            s=z.join(s)
        q=s
    else:
        q=s
    return q
# ---------------------------------------------------
def display_tag_file(filename):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    rednumber='\033[;31m'
    bluenumber ='\033[;34m'
    greennumber = '\033[;32m'
    highlightnumber = '\033[;103m'
    resetnumber='\033[0m'
    fn=open(filename, 'r', encoding='utf-8')
    for line in fn:
        if "<" in line and ">" in line and "</>" in line:
            line=line.replace("<red>",rednumber)
            line=line.replace("<blue>",bluenumber)
            line=line.replace("<green>",greennumber)
            line=line.replace("</>",resetnumber)
            print(line)
        else:
            print(line)
    fn.close()

6230098921: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display0.0FileNotFoundError("No such file or directory: 'มหาจุฬาลงกรณ์-tag.txt'")
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 456, 'const': 601, 'code+const': 1057}
def red(s):
    return RED+s+RESET
# ---------------------------------------------------
def green(s):
    return GREEN+s+RESET
# ---------------------------------------------------
def blue(s):
    return BLUE+s+RESET
# ---------------------------------------------------
def highlight(s):
    return HIGHLIGHT+s+RESET
# ---------------------------------------------------
def color_text(s, color):
    color_n = color.lower()
    if color_n == 'red' :
        return RED+s+RESET
    elif color_n == 'green' :
        return GREEN+s+RESET
    elif color_n == 'blue' :
        return BLUE+s+RESET
    else :
        return s
# ---------------------------------------------------
def color_tag(s):
    if s[0:5:] == '<red>' :
        return RED+s[5:-3:]+RESET
    elif s[0:7:] == '<green>' :
        return GREEN+s[7:-3:]+RESET
    elif s[0:6:] == '<blue>' :
        return BLUE+s[6:-3:]+RESET
# --------------------------------------------------
def highlight_words(s, words):
    for e in words :
        s_list = s.split(e)
        s = highlight(e).join(s_list)
    return s
# ---------------------------------------------------
def display_tag_file(filename):
    fin = open('มหาจุฬาลงกรณ์-tag.txt', 'r', encoding='utf-8')
    for line in fin :
        if ('<red>' in line or '<green>' in line or '<blue>' in line ) and '</>' in line :
            print(line.replace('<red>',RED).replace('<green>',GREEN).replace('<blue>',BLUE).replace('</>',RESET))
        else :
            print(line)

6230141121: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display0.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 404, 'const': 338, 'code+const': 742}
def red(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return RED + s + RESET
# ---------------------------------------------------
def green(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return GREEN + s + RESET
# ---------------------------------------------------
def blue(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return BLUE + s + RESET
# ---------------------------------------------------
def highlight(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return HIGHLIGHT + s + RESET
# ---------------------------------------------------
def color_text(s, color):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    t = color.lower()
    if t == 'red' :
        return red(s)
    if t == 'blue' :
        return blue(s)
    if t == 'green' :
        return green(s)
    else :
        return s
# ---------------------------------------------------
def color_tag(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    p1 = s.find('<')
    p2 = s.find('>')
    p3 = s.find('/')
    t = s[p1+1:p2]
    if t == 'red' :
        return red(s[p2+1:p3-1])
    if t == 'blue' :
        return blue(s[p2+1:p3-1])
    if t == 'green' :
        return green(s[p2+1:p3-1])
# ---------------------------------------------------
def highlight_words(s, words):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    for word in words:
        if (word.lower() in s.lower()):
           s = s.split(word)
           s= highlight(word).join(s)
    return s
# ---------------------------------------------------
def display_tag_file(filename):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    pass

6230148621: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_21.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display1.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 602, 'const': 439, 'code+const': 1041}
def red(s):
    return RED + s + RESET
# ---------------------------------------------------
def green(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return GREEN + s + RESET
# ---------------------------------------------------
def blue(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return BLUE + s + RESET
# ---------------------------------------------------
def highlight(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return HIGHLIGHT + s + RESET
# ---------------------------------------------------
def color_text(s, color):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    colors = color.lower()
    if colors == 'red' :
        return red(s)
    elif colors == 'green' :
        return green(s)
    elif colors == 'blue' :
        return blue(s)
    else :
        return s
# ---------------------------------------------------
def color_tag(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    a = s.find('>')
    color = s[1:a]
    text = s[a+1:-3]
    return color_text(text, color)
# ---------------------------------------------------
def highlight_words(s, words):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    lower_s = s.lower()
    for word in words:
        lower_word = word.lower()
        idx = 0
        start = 0
        end = 0
        while idx < len(s):
            start = lower_s.find(lower_word, idx)
            if(start != -1):
                end = start + len(word)
                s = s[:start] + highlight(s[start:end]) + s[end:]
                lower_s = lower_s[:start] + highlight(lower_s[start:end]) + lower_s[end:]
            else:
                end = len(s)
            idx = end + len(highlight(""))
    return s
# ---------------------------------------------------
def display_tag_file(filename):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    file = open(filename, 'r', encoding='utf-8')
    m = ''
    for line in file:
        m += line
    file.close()
    s = 0
    y = ''
    while s < len(m) :
        if m[s] == '<' :
            b = m.find('<', s+1)
            y += color_tag(m[s:b+3])
            s = b+3
        else :
            y += m[s]
            s += 1
    print(y)

6230168121: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display0.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 374, 'const': 815, 'code+const': 1189}
def red(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return ('\033[;31m' + s + '\033[0m')
# ---------------------------------------------------
def green(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return ('\033[;32m' + s + '\033[0m')
# ---------------------------------------------------
def blue(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทนz
    return ('\033[;34m' + s + '\033[0m')
# ---------------------------------------------------
def highlight(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return ('\033[;103m' + s + '\033[0m')
# ---------------------------------------------------
def color_text(s, color):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
        if color.lower() == 'red':
            return ('\033[;31m' + s + '\033[0m')
        else:
            if color.lower() == 'green':
                return ('\033[;32m' + s + '\033[0m')
            else:
                if color.lower() == 'blue':
                    return ('\033[;34m' + s + '\033[0m')
                else:
                    return(s)
# ---------------------------------------------------
def color_tag(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    j=s
    j=j[:-3:]+'\033[0m'
    if j[1:4:]=="red":
        j='\033[;31m'+j[5::]
    if j[1:6:]=="green" :
        j='\033[;32m'+j[7::]
    if j[1:5:]=="blue" :
        j='\033[;34m'+j[6::]
    return j
# ---------------------------------------------------
def highlight_words(s, words):
    for i in range(len(words)):
        d=highlight(words[i])
        s=s.replace(words[i],d)
    return s
# ---------------------------------------------------
def display_tag_file(filename):
    pass

6230187021: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display1.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 630, 'const': 967, 'code+const': 1597}
def red(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return '\033[;31m'+s+'\033[0m'
# ---------------------------------------------------
def green(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return '\033[;32m'+s+'\033[0m'
# ---------------------------------------------------
def blue(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return '\033[;34m'+s+'\033[0m'
# ---------------------------------------------------
def highlight(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return '\033[;103m'+s+'\033[0m'
# ---------------------------------------------------
def color_text(s, color):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    if color.lower() == 'red':
        return red(s)
    elif color.lower() == 'green':
        return green(s)
    elif color.lower() == 'blue':
        return blue(s)
    else:
        return s
# ---------------------------------------------------
def color_tag(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    if s[:5]=='<red>'and s[-3:]=='</>':
        return '\033[;31m'+ s[5:-3] +'\033[0m' 
    elif s[:7]=='<green>'and s[-3:]=='</>':
        return '\033[;32m' + s[7:-3] +'\033[0m' 
    elif s[:6]=='<blue>'and s[-3:]=='</>':
        return '\033[;34m'+ s[6:-3] + '\033[0m'
# ---------------------------------------------------
def highlight_words(s, words):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    for word in words:
        s = s.replace(word,highlight(word))
    return s
# ---------------------------------------------------
def display_tag_file(filename):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    infile = open(filename, 'r', encoding='utf-8')
    readfile = ''
    showfile = ''
    for line in infile:     
        readfile = readfile + line
    while len(readfile) != 0:
        ired = readfile.find('<red>')
        igreen = readfile.find('<green>')
        iblue = readfile.find('<blue>')
        istart = [ired, igreen, iblue]
        istart = [i for i in istart if i != -1]
        if len(istart) != 0:
            istart = min(istart)
            iend = readfile.find('</>') + 3
            colortxt = color_tag(readfile[istart:iend])
            showfile = showfile + readfile[:istart] + colortxt
            readfile = readfile[iend:]
        else :
            showfile = showfile + readfile
            readfile = ''
    print(showfile)

6230259621: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display0.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggo<red>rr</>z<blue>bbbbbbabc
[]
bytecount: {'code': 636, 'const': 467, 'code+const': 1103}
def red(s):
    red1=RED+s+RESET
    return red1
# ---------------------------------------------------
def green(s):
    green1=GREEN+s+RESET
    return green1
# ---------------------------------------------------
def blue(s):
    blue1=BLUE+s+RESET
    return blue1
# ---------------------------------------------------
def highlight(s):
    h1=HIGHLIGHT+s+RESET
    return h1
# ---------------------------------------------------
def color_text(s, color):
    if color.upper()=='RED':
        return red(s)
    elif color.upper()=='BLUE':
        return blue(s)
    elif color.upper()=='GREEN':
        return green(s)
    else:
        return s
# ---------------------------------------------------
def color_tag(s):
    if '<red>' in  s:
        i=s.find('<red>')
        k=s.find('</>')
        return red(s[i+len('<red>'):k])
    elif '<green>' in  s:
        i=s.find('<green>')
        k=s.find('</>')
        return green(s[i+len('<green>'):k])
    else:
        i=s.find('<blue>')
        k=s.find('</>')
        return blue(s[i+len('<blue>'):k])
# ---------------------------------------------------
def highlight_words(s, words):
    for i in words:
        s = s.replace(i,highlight(i))
    return s
# ---------------------------------------------------
def display_tag_file(filename):
    u=open(filename, 'r', encoding='utf-8')
    lines=''
    for line in u:
        p=0
        s=line.find('<',p)
        if s>=0:
            lines+=line[:s]
        else:
            lines+=line[:]
        while s>=0:
            t=line.find('</>',s)
            g=line[s:t+3]
            lines+=color_tag(g)
            p+=(t+3)
            s=line.find('<',p)
            if s>=0:
                lines+=line[t+3:s]
            else:
                lines+=line[t+3:]
    u.close()
    print(lines)

6230322421: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display0.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 356, 'const': 933, 'code+const': 1289}
def red(s):
    k = '\033[;31m' + s + '\033[0m'
    return k
# ---------------------------------------------------
def green(s):
    k = '\033[;32m' + s + '\033[0m'
    return k
# ---------------------------------------------------
def blue(s):
    k = '\033[;34m' + s + '\033[0m'
    return k
# ---------------------------------------------------
def highlight(s):
    k = '\033[;103m' + s + '\033[0m'
    return k
# ---------------------------------------------------
def color_text(s, color):
    f = color.lower()
    k = s
    if f == 'red':
        k = '\033[;31m' + s + '\033[0m'
    if f == 'green':
        k = '\033[;32m' + s + '\033[0m'
    if f == 'blue':
        k = '\033[;34m' + s + '\033[0m'
    return k
# ---------------------------------------------------
def color_tag(s):
    s1 = s.replace('<red>','\033[;31m')
    s2 = s1.replace('<green>','\033[;32m')
    s3 = s2.replace('<blue>','\033[;34m')
    s4 = s3.replace('</>','\033[0m')        
    return s4
# ---------------------------------------------------
def highlight_words(s, words):
    s1 = ''
    for e in words:
        s1 = s.replace(e,'\033[;103m'+ e + '\033[0m'  )
        s = s1
    return s1
# ---------------------------------------------------
def display_tag_file(filename):
    fin = open(filename, 'r', encoding='utf-8')
    t = fin.read()
    t1 = color_tag(t)
    t2 = color_tag(t1)
    fin.close()
    return t1

6230425421: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display1.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 358, 'const': 360, 'code+const': 718}
def red(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return RED + s + RESET
# ---------------------------------------------------
def green(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return GREEN + s + RESET
# ---------------------------------------------------
def blue(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return BLUE + s + RESET
# ---------------------------------------------------
def highlight(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return HIGHLIGHT + s + RESET
# ---------------------------------------------------
def color_text(s, color):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    color = color.lower()
    if color == 'red':
      return red(s)
    elif color == 'green':
      return green(s)
    elif color == 'blue':
      return blue(s)
    else :
      return s
# ---------------------------------------------------
def color_tag(s):
    s = s.replace('</>',RESET)
    s = s.replace('<red>', RED)
    s = s.replace('<green>', GREEN)
    s = s.replace('<blue>', BLUE)
    return s
# ---------------------------------------------------
def highlight_words(s, words):
    for e in words :
        idx = s.find(e)
        n = s[idx:idx+len(e)]
        if n in s :
            n = HIGHLIGHT + n + RESET
            s = s.replace(e,n)
    return s
# ---------------------------------------------------
def display_tag_file(filename):
    file = open(filename, 'r', encoding='utf-8')
    p = file.read()
    print(color_tag(p))

6231010821: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_10.0
[Non'\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0
[Non'\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display0.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 348, 'const': 629, 'code+const': 977}
def red(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    w = '\033[;31m'+s+'\033[0m'
    return w
# ---------------------------------------------------
def green(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    w = '\033[;32m'+s+'\033[0m'
    return w
# ---------------------------------------------------
def blue(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    w = '\033[;34m'+s+'\033[0m'
    return w
# ---------------------------------------------------
def highlight(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    w = '\033[;103m'+s+'\033[0m'
    return w
# ---------------------------------------------------
def color_text(s, color):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    if color == "red" :
        a = '\033[;31m'+s+'\033[0m'
    elif color == "green" :
        a = '\033[;32m'+s+'\033[0m'
    elif color == "blue" :
        a = '\033[;34m'+s+'\033[0m'
    else :
        a = s
    return a
# ---------------------------------------------------
def color_tag(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    u = s[1:]
    d = ''
    for i in u :
        if i != ">" :
            d = d + str(i)
        else :
            break
    f = len(d)+2
    dd = s[f:]
    g = ''
    for i in dd :
        if i != "<" :
            g = g + str(i)
        else :
            break
    aaa = color_text(g, d)
    return aaa
# ---------------------------------------------------
def highlight_words(s, words):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    pass
# ---------------------------------------------------
def display_tag_file(filename):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    pass

6231110921: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_10.0NameError("name 't' is not defined")
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0NameError("name 't' is not defined")
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display0.0Time-out: 3s
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 616, 'const': 665, 'code+const': 1281}
def red(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return RED+s+RESET
# ---------------------------------------------------
def green(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return GREEN+s+RESET
# ---------------------------------------------------
def blue(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return BLUE+s+RESET
# ---------------------------------------------------
def highlight(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return HIGHLIGHT+s+RESET
# ---------------------------------------------------
def color_text(s, color):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    if color in [ 'red','RED','Red','REd','ReD','rEd','rED','reD']:
      return red(s)
    elif color in ['GREEN','GREEn','GREeN','GREen','GReEN','GReEn','GReeN','GReen','GrEEN','GrEEn','GrEeN','GrEen','GreEN','GreEn','GreeN','Green','gREEN','gREEn','gREeN','gREen','gReEN','gReEn','gReeN','gReen','grEEN','grEEn','grEeN','grEen','greEN','greEn','greeN','green']:
      return green(s)
    elif color in ['BLUE','BLUe','BLuE','BLue','BlUE','BlUe','BluE','Blue','bLUE','bLUe','bLuE','bLue','blUE','blUe','bluE','blue']:
      return blue(s)
    else:
      return s
#---------------------------------------------------
def color_tag(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    w = ""
    color = ""
    for i in range(1,len(s)-3):
      while s[i] != '>':
        color+=s[i]
        i+=1 
      break
    index = s.find('>')
    for j in range(index+1,len(s)-3):
      w += s[j]
    return color_text(w,color)
# ---------------------------------------------------
def highlight_words(s, words):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    words = str(words)[2:-2]
    w = ""
    j = s.find(words)
    for i in range(len(t)):
      if i<j or i>=j+len(words):
        w+=t[i]
      elif i == j:
        w+= highlight(words)
      while j<=i<j+len(words):
        break
      if j != -1 and i>j and i>j+len(words):
        j = t.find(words,j+len(words))
    return w 
# ---------------------------------------------------
def display_tag_file(filename):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    file = open(filename, 'r', encoding='utf-8')
    line = file.readline()
    for line in file:
      w = ""
      for i in range(len(line)):
        while line[i] != '>':
          if line[i] == '<':
            w+=line[i:]

6231117321: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_10.0NameError("name 't' is not defined")
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0NameError("name 't' is not defined")
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display0.0ValueError("Can't open with mode: r+")
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 814, 'const': 534, 'code+const': 1348}
def red(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
     return str(RED+s+RESET)
# ---------------------------------------------------
def green(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return str(GREEN+s+RESET)
# ---------------------------------------------------
def blue(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return str(BLUE+s+RESET)
# ---------------------------------------------------
def highlight(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return str(HIGHLIGHT+s+RESET)
# ---------------------------------------------------
def color_text(s,color):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    lower_color = color.lower()
    if  lower_color == 'red'  :
        return (red(s))
    elif  lower_color == 'blue' :
        return (blue(s))
    elif  lower_color == 'green' :
        return (green(s))
    else:
        return (s)
# จะ สร้าง GReen GrEEn GREEn
# ---------------------------------------------------
def color_tag(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    idx = s.find('>')
    idx2 = s.find('<',2) #ไปเริ่มค้น idx ที่ 2 not หา...ครั้งที่2
    cut_s = s[idx+1:idx2]
    if s[1] == "r":
        return (red(s))
    elif s[1] == 'g':
        return (green(s))
    elif s[1] == 'b':
        return (blue(s))
# ---------------------------------------------------
def highlight_words(s, words):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    if len(words) == 0:
        print(t)
    elif len(words) == 1:
        if words[0] in t:
            new = t.replace(words[0],highlight(words[0]))
            return (new)
    else:
        if words[0] in t:
            new = t.replace(words[0],highlight(words[0]))
        for i in range(1,len(words)):
            if words[i] in t:
                new2 = new.replace(words[i],highlight(words[i]))
                new = new2
    return (new2)
# ---------------------------------------------------
def display_tag_file(filename):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    with open(filename ,mode='r+',encoding = 'utf-8') as doc:
        for line in doc:
            line = line.rstrip()
            idx1 = line.find('<')
            num = line.count('<')
            if idx1 == -1: # เจอไม่เจอ
                print(line)
            else:
                text = []
                turn = 0
                i = 0 
                while turn <= (num//2):
                    idx2 = line.find('>',i) #  หา > ครั้งที่ 1
                    idx3 = line.find('>',idx2+1)
                    text.append(line[idx1:idx3+1])
                    i += idx3
                    if line.find('<',i) == -1 :
                        break
                    else:
                         idx4 = line.find('<',i) #  หา > ครั้งที่ 1
                         idx5 = line.find('>',idx4+1)
                         idx6 = line.find('>',idx5+1)
                         text.append(line[idx4:idx6+1])
                         i += idx6
                turn+=1
                #print(text)
                for ele in text:
                    line_new = line.replace(ele,color_tag(ele))
                    line = line_new
                print(line_new)

6231120121: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display0.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 412, 'const': 351, 'code+const': 763}
def red(s):
  s  = (RED+s+RESET)
  return s 
# ---------------------------------------------------
def green(s):
  s = (GREEN+s+RESET)
  return s 
# ---------------------------------------------------
def blue(s):
  s = (BLUE+s+RESET)
  return s 
# ---------------------------------------------------
def highlight(s):
  s = (HIGHLIGHT+s+RESET)
  return s 
# ---------------------------------------------------
def color_text(s, color):
    cl = color.lower()
    if cl == "red" :
        s = (RED+s+RESET)
    if cl == "blue" :
        s = (BLUE+s+RESET)
    if cl == "green" :
        s = (GREEN+s+RESET)
    else:
        s = s
    return s
# ---------------------------------------------------
def color_tag(s):
    inp     = s[1:-3].split(">")
    text    = inp[1]
    color   = inp[0]
    if color == "red" :
        s = (RED+text+RESET)
    if color == "blue" :
        s = (BLUE+text+RESET)
    if color == "green" :
        s = (GREEN+text+RESET)
    return s
# ---------------------------------------------------
def highlight_words(s, words):
    if len(words) == 0:
      return s
    else:
      for i in words:
          spl = s.split(i)
          s = ""
          for e in spl:
            s += e+highlight(i)
          s = s[:-(len(highlight(i)))]
      return s
# ---------------------------------------------------
def display_tag_file(filename):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    pass

6231121821: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display0.0FileNotFoundError("No such file or directory: 'filename'")
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 656, 'const': 961, 'code+const': 1617}
def red(s):
    return '\033[;31m' + s + '\033[0m'
# ---------------------------------------------------
def green(s):
    return '\033[;32m' + s + '\033[0m'
# ---------------------------------------------------
def blue(s):
    return '\033[;34m' + s + '\033[0m'
# ---------------------------------------------------
def highlight(s):
    return '\033[;103m' + s + '\033[0m'
# ---------------------------------------------------
def color_text(s, color):
    if color.lower() == 'blue':
      a = blue(s)
    elif color.lower() == 'green':
      a = green(s)
    elif color.lower() == 'red':
      a = red(s)
    else:
      a = s
    return a
# ---------------------------------------------------
def color_tag(s):
    s = s[0:-3]
    if s[0:5] == '<red>':
      a = color_text(s[5:], 'red')
    elif s[0:7] == '<green>':
      a = color_text(s[7:], 'green')
    elif s[0:6] == '<blue>':
      a = color_text(s[6:], 'blue')
    return a
# ---------------------------------------------------
def highlight_words(s, words):
    w = str(s)
    for i in range(len(words)):
      new = ''
      while w.find(words[i]) > -1:
        start = 0
        a = w.find(words[i])  
        k = w[a:a+len(words[i])]
        new += w[start:a] + highlight(k)
        w = w[a+len(words[i]):]
      new += w
      w = new
    return new
# ---------------------------------------------------
def display_tag_file(filename):
  f1 = open('filename', 'r', encoding='utf-8')
  nline = ''
  for line in f1:
      newline = ''
      while line.find('<') > -1:
          start = 0
          a = line.find('<')
          b = line.find('</>')
          k = color_tag(line[a:b+3])
          newline += line[start:a] + k
          line = line[b+3:]
      newline += line
      nline += newline + '\n'
  f1.close()
  print(nline)

6231122421: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display1.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 442, 'const': 441, 'code+const': 883}
def red(s):
    return RED+s+RESET
# ---------------------------------------------------
def green(s):
    return GREEN+s+RESET
# ---------------------------------------------------
def blue(s):
    return BLUE+s+RESET
# ---------------------------------------------------
def highlight(s):
    return HIGHLIGHT+s+RESET
# ---------------------------------------------------
def color_text(s, color):
    color = color.lower()
    if color == 'red':
        return red(s)
    elif color == 'green':
        return green(s)
    elif color == 'blue':
        return blue(s)
    else:
        return s
# ---------------------------------------------------
def color_tag(s):
    s = s.split('</>')
    ans = ''
    for i in range(len(s)-1):
        e = s[i].split('>')
        text = e[0].split('<')
        temp = color_text(e[1], text[1])
        ans += text[0] + temp
    ans += s[-1]
    return ans
# ---------------------------------------------------
def highlight_words(s, words):
    ans = s
    for e in words:
        temp = ans.split(e)
        temp1 = ''
        for i in range(len(temp)-1):
            temp1 += temp[i] + highlight(e)
        temp1 += temp[-1]
        ans = temp1
    return ans
# ---------------------------------------------------
def display_tag_file(filename):
    f = open(filename, 'r', encoding='utf-8')
    text = f.read()
    print(color_tag(text))

6231127621: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display1.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 328, 'const': 481, 'code+const': 809}
def red(s):
    return RED + s + RESET
# ---------------------------------------------------
def green(s):
    return GREEN + s + RESET
# ---------------------------------------------------
def blue(s):
    return BLUE + s + RESET
# ---------------------------------------------------
def highlight(s):
    return HIGHLIGHT + s + RESET
# ---------------------------------------------------
def color_text(s, color):
    if color.lower() == 'red':
        return RED + s + RESET
    if color.lower() == 'green':
        return GREEN + s + RESET
    if color.lower() == 'blue':
        return BLUE + s + RESET
    return s
# ---------------------------------------------------
def color_tag(s):
    return s.replace('<red>', RED).replace('<green>', GREEN).replace('<blue>', BLUE).replace('</>', RESET)
# ---------------------------------------------------
def highlight_words(s, words):
    for word in words:
        s = s.replace(word, HIGHLIGHT + word + RESET)
    return s
# ---------------------------------------------------
def display_tag_file(filename):
    fp = open(filename, 'r', encoding='utf-8')
    s = fp.read()
    print(s.replace('<red>', RED).replace('<green>', GREEN).replace('<blue>', BLUE).replace('</>', RESET))

6231129921: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display0.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 780, 'const': 670, 'code+const': 1450}
def red(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    a = RED + s + RESET
    return a
# ---------------------------------------------------
def green(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    a = GREEN + s + RESET
    return a
# ---------------------------------------------------
def blue(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    a = BLUE + s + RESET
    return a
# ---------------------------------------------------
def highlight(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    a = HIGHLIGHT + s + RESET
    return a
# ---------------------------------------------------
def color_text(s, color):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    if color.lower() == 'red':
        a = red(s)
        return a
    elif color.lower() == 'green':
        a = green(s)
        return a
    elif color.lower() == 'blue':
        a = blue(s)
        return a
    else:
        return s
# ---------------------------------------------------
def color_tag(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    a = ''
    if s[0:5] == '<red>':
        a += s[5:-3]
        return red(a)
    elif s[0:7] == '<green>':
        a += s[7:-3]
        return green(a)
    elif s[0:6] == '<blue>':
        a += s[6:-3]
        return blue(a)
# ---------------------------------------------------
def highlight_words(s, words):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    a = ''
    if len(words) == 0:
        return s
    else:
        for e in words:
            # word[0]
            # e == 'มิใช่'
            b = highlight(e)
            s = s.replace(e,b)   
        return s
def display_tag_file(filename):
    f1 = open(filename, 'r', encoding='utf-8')
    text =''
    for line in f1:
      text += line
    f1.close()
    for i in range(len(text)):
      if text[i:i+5] == '<red>':
        k1 = text.index('<red>') # ได้ index red
        k2 = text.index('</>',k1) # ได้ index <
        w = ''
        w += text[k1+5:k2]
        text = text.replace(text[i:k2+3],red(w))
      elif text[i:i+7] == '<green>':
        k1 = text.index('<green>') # ได้ index green
        k2 = text.index('</>',k1) # ได้ index <
        w = ''
        w += text[k1+7:k2]
        text = text.replace(text[i:k2+3],green(w))
      elif text[i:i+6] == '<blue>':
        k1 = text.index('<blue>') # ได้ index blue
        k2 = text.index('</>',k1) # ได้ index <
        w = ''
        w += text[k1+6:k2]
        text = text.replace(text[i:k2+3],blue(w))
    return text

6231130421: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display1.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 426, 'const': 398, 'code+const': 824}
def red(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return RED+s+RESET
# ---------------------------------------------------
def green(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return GREEN+s+RESET
# ---------------------------------------------------
def blue(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return BLUE+s+RESET
# ---------------------------------------------------
def highlight(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return HIGHLIGHT+s+RESET
# ---------------------------------------------------
def color_text(s, color):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    color = color.strip().lower()
    if color == "red":
      return red(s)
    elif color == "green":
      return green(s)
    elif color == "blue":
      return blue(s)
    return s
# ---------------------------------------------------
def color_tag(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    color = s[s.find("<")+1:s.find(">")]
    text = s[s.find(">")+1:s.rfind("<")]
    return color_text(text,color)
# ---------------------------------------------------
def highlight_words(s, words):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    text = s
    for word in words:
      text = text.replace(word, highlight(word))
    return text
# ---------------------------------------------------
def display_tag_file(filename):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    f = open(filename, "r")
    lines = f.readlines()
    f.close()
    lines = [line.strip() for line in lines]
    text = "\n".join(lines)
    text = text.replace("<red>",RED)
    text = text.replace("<green>",GREEN)
    text = text.replace("<blue>",BLUE)
    text = text.replace("</>",RESET)
    print(text)

6231401521: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display0.0FileNotFoundError("No such file or directory: 'มหาจุฬาลงกรณ์-tag.txt'")
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 566, 'const': 1424, 'code+const': 1990}
def red(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    x = RED + s + RESET
    return x
# ---------------------------------------------------
def green(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    x = GREEN + s + RESET
    return x
# ---------------------------------------------------
def blue(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    x = BLUE + s + RESET
    return x
# ---------------------------------------------------
def highlight(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    x = HIGHLIGHT + s + RESET
    return x
# ---------------------------------------------------
def color_text(s, color):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    if color.upper() == "RED":
        x = RED + s + RESET
        return x
    else:
        if color.upper() == "GREEN":
            x = GREEN + s + RESET
            return x
        else:
            if color.upper() == "BLUE":
                x = BLUE + s + RESET
                return x
# ---------------------------------------------------
def color_tag(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    a = s[1:]
    b = a.find('>')
    x = a[:b]
    y = a[b+1:-3]
    z = color_text(y, x)
    return z
# ---------------------------------------------------
def highlight_words(s, words):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    for i in words:
        s = s.replace(i,highlight(i))
    return s
# ---------------------------------------------------
def display_tag_file(filename):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    with open('มหาจุฬาลงกรณ์-tag.txt', 'r', encoding='utf-8') as file:
      data = file.read()
    for i in range(len(data)):
      a = color_text('สีชมพู', 'red')
      b = color_text('จุฬาลงกรณ์', 'blue')
      c = color_text('พระนาม', 'green')
      d = color_text('องค์', 'red')
      e = color_text('อาทร', 'blue')
      f = color_text('นิสิต', 'green')
      g = color_text('พระเกียรติ', 'red')
      h = color_text('พระเกี้ยว', 'red')
      data = data.replace('<red>สีชมพู</>', a)
      data = data.replace('<blue>จุฬาลงกรณ์</>', b)
      data = data.replace('<green>พระนาม</>', c)
      data = data.replace('<red>องค์</>', d)
      data = data.replace('<blue>อาทร</>', e)
      data = data.replace('<green>นิสิต</>', f)
      data = data.replace('<red>พระเกียรติ</>', g)
      data = data.replace('<red>พระเกี้ยว</>', h)
    print(data)

6231404421: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display0.0ValueError('I/O operation on closed file.')
abc<ed>31mrrr</>pkk
def<reen>32mggg</>ocr
xyz<lue>34mbbb</>abc
abc<ed>31mrrr</>pf<green&gt;ggg</>o<red>rr</>z<blue>bbb</>abc
[]
bytecount: {'code': 714, 'const': 603, 'code+const': 1317}
def red(s):
    x =  RED + s + RESET
    return x
# ---------------------------------------------------
def green(s):
    x = GREEN + s + RESET
    return x
# ---------------------------------------------------
def blue(s):
    x = BLUE + s + RESET
    return x
# ---------------------------------------------------
def highlight(s):
    x = HIGHLIGHT + s + RESET
    return x
# ---------------------------------------------------
def color_text(s, color):
    if color.lower() == 'red':
        x =  RED + s + RESET
        return x
    elif color.lower() == 'blue':
        x =  BLUE + s + RESET
        return x
    elif color.lower() == 'green':
        x =  GREEN + s + RESET
        return x
    else :
        return s
def color_tag(s):
    y = s[1:]
    k = y.find('>')
    x = y[:k]
    a = y[k+1:-3]
    if x == 'red':
        z =  RED + a + RESET
        return z
    elif x == 'blue':
        z =  BLUE + a + RESET
        return z
    elif x == 'green':
        z =  GREEN + a + RESET
        return z
# ---------------------------------------------------
def highlight_words(s, words):
  for i in words :
        s = s.replace(i,highlight(i))
  return s
# ---------------------------------------------------
def display_tag_file(filename):
  a = open(filename, 'r', encoding='utf-8')
  for line in a :
    print(line.strip())
  a.close()
  z = 0
  for i in a :
      z += 1
      if i == '<' :
          if a[z-1:z+3] == 'red' :
              x = a.find('</>')
              a = a.replace(a[z+4:x+3],red(a[z+4:x]))
          if a[z-1:z+5] == 'green' :
              x = a.find('</>')
              a = a.replace(a[z+6:x+3],green(a[z+6:x]))
          if a[z-1:z+4] == 'blue' :
              x = a.find('</>')
              a = a.replace(a[z+5:x+3],blue(a[z+5:x]))
  print(a)

6231405021: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display0.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 388, 'const': 300, 'code+const': 688}
def red(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    x = RED + s + RESET
    return x
# ---------------------------------------------------
def green(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    x = GREEN + s + RESET
    return x
# ---------------------------------------------------
def blue(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    x = BLUE + s + RESET
    return x
# ---------------------------------------------------
def highlight(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    x = HIGHLIGHT + s + RESET
    return x
# ---------------------------------------------------
def color_text(s, color):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    if color.lower() == "red" :
        x = RED + s + RESET
        return x
    elif color.lower() == "blue" :
        x = BLUE + s + RESET
        return x
    elif color.lower() == "green" :
        x = GREEN + s + RESET
        return x
    else :
        return s
# ---------------------------------------------------
def color_tag(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    x = s[1:]
    y = x.find(">")
    z = x[:y]
    a = x[y + 1 :-3]
    if z == "red" :
        b = RED + a + RESET
        return b
    elif z == "blue" :
        b = BLUE + a + RESET
        return b
    elif z == "green" :
        b = GREEN + a + RESET
        return b
# ---------------------------------------------------
def highlight_words(s, words):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    for i in words :
        s = s.replace(i,highlight(i))
    return s
# ---------------------------------------------------
def display_tag_file(filename):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    pass

6231416021: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display1.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 416, 'const': 508, 'code+const': 924}
def red(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    global RED,RESET 
    return RED+s+RESET
# ---------------------------------------------------
def green(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    global GREEN,RESET
    return GREEN+s+RESET
# ---------------------------------------------------
def blue(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    global BLUE,RESET
    return BLUE+s+RESET
# ---------------------------------------------------
def highlight(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    global HIGHLIGHT ,RESET
    return HIGHLIGHT+s+RESET
# ---------------------------------------------------
def color_text(s,color):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    if color.lower() =='red':
      return red(s)
    elif color.lower() =='blue':
      return blue(s)
    elif color.lower() =='green':
      return green(s)
    else:
      return s
# ---------------------------------------------------
def color_tag(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    if "<red>" in s and "</>" in s:
      return red(s.replace("<red>","").replace("</>",""))
    elif "<green>" in s and "</>" in s:
      return green(s.replace("<green>","").replace("</>",""))
    elif "<blue>" in s and "</>" in s:
      return blue(s.replace("<blue>","").replace("</>",""))
# ---------------------------------------------------
def highlight_words(s, words):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    for word in words:
      s = s.replace(word,highlight(word))
    return s
# ---------------------------------------------------
def display_tag_file(filename):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    global RED,GREEN,BLUE,RESET
    print(open(filename, 'r', encoding='utf-8').read().replace("<red>",RED).replace("<green>",GREEN).replace("<blue>",BLUE).replace("</>",RESET))

6231417621: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_10.0
['\x1b[;103m\x1b[;103mabc\x1b[0m\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103m\x1b[;103mabc\x1b[0m\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103m\x1b[;103mabc\x1b[0m\x1b[0maa\x1b[;103m\x1b[;103mabc\x1b[0m\x1b[0m']
test_highlight_20.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0mAbcAbbcbffGcd\x1b[;103mAbc\x1b[;103maAbbcbf\x1b[;103mfG\x1b[0maa\x1b[;103mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display0.0
abcrrrpkk

defgggocr

xyzbbbabc

abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 546, 'const': 724, 'code+const': 1270}
def red(s):
    x='\033[;31m'+s+'\033[0m'
    return x  
# ---------------------------------------------------
def green(s):
    x='\033[;32m'+s+'\033[0m'
    return x 
# ---------------------------------------------------
def blue(s):
    x='\033[;34m'+s+'\033[0m'
    return x 
# ---------------------------------------------------
def highlight(s):
    x='\033[;103m'+s+'\033[0m'
    return x  
# ---------------------------------------------------
def color_text(s, color):
    if color.lower() == 'red':
        x=red(s)
    elif color.lower() =='blue':
        x=blue(s)
    elif color.lower() =='green':
        x=green(s)
    else:
        x=s
    return x
# ---------------------------------------------------
def color_tag(s):
    x=s.replace('<',',').replace('>',',')
    x=x.split(',')
    for i in x:
          if i =='red':
              k=x.index(i)
              x[k+1]=red(x[k+1])
          elif i =='blue':
              k=x.index(i)
              x[k+1]=blue(x[k+1])
          elif i =='green':
              k=x.index(i)
              x[k+1]=green(x[k+1])
    r=''.join(x[0::2])
    return r
# ---------------------------------------------------
def highlight_words(s, words):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    if len(words) != 0:
      x= s.replace(words[0],highlight(words[0]))
      for i in words:
        x=x.replace(i,highlight(i))
    else:
        x=s
    return x
# ---------------------------------------------------
def display_tag_file(filename):
    f1 = open(filename, 'r', encoding='utf-8')
    for line in f1:
       x=color_tag(line)
       print(x)
    f1.close

6231422721: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0
['\x1b[;103mabcBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103maAbc\x1b[0mAbbcbf\x1b[;103mfgG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display0.0
abcrrrpkk

defgggocr

xyzbbbabc

abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 562, 'const': 521, 'code+const': 1083}
def red(s):
    return RED+s+RESET 
# ---------------------------------------------------
def green(s):
    return GREEN+s+RESET 
# ---------------------------------------------------
def blue(s):
    return BLUE+s+RESET 
# ---------------------------------------------------
def highlight(s):
    return HIGHLIGHT+s+RESET 
# ---------------------------------------------------
def color_text(s,color):
    if color.lower() == "red" :
        return red(s)
    elif color.lower() == "green" :
        return green(s)
    elif color.lower() == "blue" :
        return blue(s)
    else :
        return s
# ---------------------------------------------------
def color_tag(s):
    return color_text(s[s.find(">")+1:s.find("</>")],s[s.find("<")+1:s.find(">")])
# ---------------------------------------------------
def highlight_words(s, words):
    for i in words :
        e = 0
        c = ""
        while e < len(s)  :
            if s[e:e+len(i)].lower() == i.lower() :
                c += highlight(i)
                e += len(i)
            else :
                c += s[e]
                e += 1
        s = c
    return s 
# ---------------------------------------------------
def display_tag_file(filename):
    fn = open(filename, 'r', encoding='utf-8')
    for s in fn :
        c = ""
        i = 0
        while i < len(s) :
            if s[i] == "<" :
                c += color_tag(s[i:])
                if s[i:].find("</>") == -1 :
                    i = len(s)-1
                else :
                    i +=  s[i:].find("</>")+3
            else :
                c += s[i]
                i += 1
        print(c)
    fn.close()

6231425621: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_21.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display1.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 1032, 'const': 657, 'code+const': 1689}
def red(s):
    return RED+s+RESET
# ---------------------------------------------------
def green(s):
    return GREEN+s+RESET
# ---------------------------------------------------
def blue(s):
    return BLUE+s+RESET
# ---------------------------------------------------
def highlight(s):
    return HIGHLIGHT+s+RESET
# ---------------------------------------------------
def color_text(s, color):
    color = color.upper()
    if color == "RED":
        return red(s)
    if color == "BLUE":
        return blue(s)
    if color == "GREEN":
        return green(s)
    return s
# ---------------------------------------------------
def color_tag(s):
    n_red = len('<red>')
    n_green = len('<green>')
    n_blue = len('<blue>')
    k = s.find('</>')
    if '<red>' in s:
        s1 = s[n_red:k]
        return red(s1)
    if '<green>' in s:
        s1 = s[n_green:k]
        return green(s1)
    if '<blue>' in s:
        s1 = s[n_blue:k]
        return blue(s1)
# ---------------------------------------------------
def highlight_words(s, words):
    if len(words) == 0:
        return s
    for e in words:
        k = s.lower().find(e.lower())
        if k != -1:
            s1 = s[:k]
        else:
            s1 = s
        while k != -1:
            k1 = k+len(e)
            s1 += highlight(s[k:k1])
            k = s.lower().find(e.lower(),k1)
            if k != -1:
                s1 += s[k1:k]
            else:
                s1 += s[k1:]
                break
        s=s1
    return s1
# ---------------------------------------------------
def display_tag_file(filename):
    f1 = open(filename, 'r', encoding='utf-8')
    key = ''
    for line in f1:
        line = line.strip()
        if key != '':
            st = line.find('</>')
            line = color_tag(key+line[:st+3])+line[st+3:]
        for i in range(len(line)):
            if line[i:i+2] == '<r':
                stop = line.find('</>')
                if stop != -1:
                    line = line[:i]+color_tag(line[i:stop+3])+line[stop+3:]
                    key = ''
                else:
                    line = line[:i]+color_tag(line[i:]+'</>')
                    key = '<red>'
            if line[i:i+2] == '<g':
                stop = line.find('</>')
                if stop != -1:
                    line = line[:i]+color_tag(line[i:stop+3])+line[stop+3:]
                    key = ''
                else:
                    line = line[:i]+color_tag(line[i:]+'</>')
                    key = '<green>'
            if line[i:i+2] == '<b':
                stop = line.find('</>')
                if stop != -1:
                    line = line[:i]+color_tag(line[i:stop+3])+line[stop+3:]
                    key = ''
                else:
                    line = line[:i]+color_tag(line[i:]+'</>')
                    key = '<blue>'
        print(line)
    f1.close()

6231715621: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display0.0FileNotFoundError("No such file or directory: 'มหาจุฬาลงกรณ์-tag.txt'")
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 686, 'const': 708, 'code+const': 1394}
def red(s):
    return RED+s+RESET
# ---------------------------------------------------
def green(s):
    return GREEN+s+RESET
# ---------------------------------------------------
def blue(s):
    return BLUE+s+RESET
# ---------------------------------------------------
def highlight(s):
    return HIGHLIGHT+s+RESET
# ---------------------------------------------------
def color_text(s, color):
    color = color.lower()
    if color == 'red':
        return RED+s+RESET 
    elif color == 'green':
        return GREEN+s+RESET 
    elif color == 'blue':
        return BLUE+s+RESET 
    else :
        return s
# ---------------------------------------------------
def color_tag(s):
    first_find = s.find('>')
    second_find = s.find('<',first_find)
    new_s = s[first_find+1:second_find]
    if '<red>' in s :
        return RED+new_s+RESET
    elif '<green>' in s : 
        return GREEN+new_s+RESET
    elif '<blue>' in s :
        return BLUE+new_s+RESET
# ---------------------------------------------------
def highlight_words(s, words):
    new_s = ''
    if words == []:
        new_s = s
    for e in words:
        if e in s:
            new_s = s.replace(e,HIGHLIGHT+e+RESET)
            s = new_s
        elif e not in s :
            new_s = s
    return new_s
# ---------------------------------------------------
def display_tag_file(filename):
    infile = open('มหาจุฬาลงกรณ์-tag.txt', 'r', encoding='utf-8')
    for line in infile:
        new_line = line.strip('\n')
        line = new_line
        if '<red>' in line:
            c = line.find('<red>')
            d = line.find('</>',c)
            word_colored = red(line[c+5:d])
            new_line = line[:c]+word_colored+line[d+3:]
        if '<green>' in line:
            c = new_line.find('<green>')
            d = new_line.find('</>',c)
            word_colored = green(new_line[c+7:d])
            new_line = new_line[:c]+word_colored+new_line[d+3:]
        if '<blue>' in line:
           c = new_line.find('<blue>')
           d = new_line.find('</>',c)
           word_colored = blue(new_line[c+6:d])
           new_line = new_line[:c]+word_colored+new_line[d+3:]
        print(new_line)    
    infile.close()

6231718521: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_10.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display0.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 424, 'const': 412, 'code+const': 836}
def red(s):
    s=RED+s+RESET
    return s
# ---------------------------------------------------
def green(s):
    s=GREEN+s+RESET
    return s
# ---------------------------------------------------
def blue(s):
    s=BLUE+s+RESET
    return s
# ---------------------------------------------------
def highlight(s):
    s=HIGHLIGHT+s+RESET
    return s
# ---------------------------------------------------
def color_text(s, color):
    color=color.upper()
    if color == "RED":
        return red(s)
    if color == "GREEN":
        return green(s)
    if color == "BLUE":
        return blue(s)
    else:
        return s
# ---------------------------------------------------
def color_tag(s):
    if "<red>" in s:
        s=s.split("<red>")[1]
        s=s.split("</>")[0]
        return color_text(s,red)
    if "<green>" in s:
        s=s.split("<green>")[1]
        s=s.split("</>")[0]
        return color_text(s,green)
    if "<blue>" in s:
        s=s.split("<blue>")[1]
        s=s.split("</>")[0]
        return color_text(s,blue)
# ---------------------------------------------------
def highlight_words(s, words):
    for m in words:
        s=s.replace("m",highlight(m))
    return s
# ---------------------------------------------------
def display_tag_file(filename):
    infile=open(filename, 'r', encoding='utf-8')
    data = infile.read()
    infile.close()

6231720721: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display0.0
abcrrrpkk

defgggocr

xyzbbbabc

abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 544, 'const': 637, 'code+const': 1181}
def red(s):
    r = '\033[;31m'+s+'\033[0m'
    return r
# ---------------------------------------------------
def green(s):
    g = '\033[;32m'+s+'\033[0m'
    return g
# ---------------------------------------------------
def blue(s):
    b = '\033[;34m'+s+'\033[0m'
    return b
# ---------------------------------------------------
def highlight(s):
    h = '\033[;103m'+s+'\033[0m'
    return h
# ---------------------------------------------------
def color_text(s, color):
    color = color.lower()
    if color == 'red':
        return red(s)
    elif color == 'green':
        return green(s)
    elif color == 'blue':
        return blue(s)
    else:
        return s
# ---------------------------------------------------
def color_tag(s):
    c=0
    for i in range(len(s)):
        if s[i] == '/':
            c+=1
    k=0
    tt=''
    y2=-1
    while k<c:
        x1 = s.find('<',y2+1)
        y1 = s.find('>',y2+1)
        x2 = s.find('<',x1+1)
        tt+=s[y2+1:x1]+color_text(s[y1+1:x2],s[x1+1:y1])
        y2 = s.find('>',y1+1)
        k+=1
    tt+=s[y2+1:]
    return tt
# ---------------------------------------------------
def highlight_words(s, words):
    if len(words) != 0:
        for i in range(len(words)):
            s=s.replace(words[i],highlight(words[i]))
        return s
    else:
        return s
# ---------------------------------------------------
def display_tag_file(filename):
    fn = open(filename,'r',encoding='utf-8')
    for line in fn:
        print(color_tag(line))
    fn.close()
# display_tag_file('มหาจุฬาลงกรณ์-tag.txt')

6330175621: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display0.0
abcrrrpkk

defgggocr

xyzbbbabc

abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 570, 'const': 816, 'code+const': 1386}
def red(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return '\033[;31m'+s+'\033[0m'
# ---------------------------------------------------
def green(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return '\033[;32m'+s+'\033[0m'
# ---------------------------------------------------
def blue(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return '\033[;34m'+s+'\033[0m'
# ---------------------------------------------------
def highlight(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return '\033[;103m'+s+'\033[0m'
# ---------------------------------------------------
def color_text(s, color):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    if color.lower() == 'red':
        return red(s)
    elif color.lower() == 'green':
        return green(s)
    elif color.lower() == 'blue':
        return blue(s)
    else:
        return s
# ---------------------------------------------------
def color_tag(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    start = s.find('<')
    end = s.find('>')
    read = s[start+1:end] 
    reset = s.find('</>')
    m = s[end+1:reset]
    if read == 'red':
        return s.replace(s[start:reset+3],color_text(m,'red'))
    elif read == 'blue':
        return s.replace(s[start:reset+3],color_text(m,'blue'))
    elif read == 'green':
        return s.replace(s[start:reset+3],color_text(m,'green'))
    else:
        return s
# ---------------------------------------------------
def highlight_words(s, words):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    if len(words) != 0:
        for e in words:
            c = s.find(e)
            if c >= 0:
                s = s.replace(e,'\033[;103m'+e+'\033[0m')
    return s
# ---------------------------------------------------
def display_tag_file(filename):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    f1 = open(filename, 'r', encoding='utf-8')
    for line in f1:
        st = 0
        stop = 0
        while stop != -1:
            code = line
            stop = code.find('</>',st+3)
            if stop != -1:
                code = line[st:stop+3]
                line = line.replace(code,color_tag(code))
                st = stop+3
        print(line)

6331112221: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_10.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display0.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 554, 'const': 518, 'code+const': 1072}
def red(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return RED + s + RESET
# ---------------------------------------------------
def green(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return GREEN + s + RESET
# ---------------------------------------------------
def blue(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return BLUE + s + RESET
# ---------------------------------------------------
def highlight(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return HIGHLIGHT + s + RESET
# ---------------------------------------------------
def color_text(s, color):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    out = ""
    if color[0] == "r" or color[0] == "R":
        out += red(s)
    elif color[0] == "g" or color[0] == "G":
        out += green(s)
    elif color[0] == "b" or color[0] == "B":
        out += blue(s)
    elif color[0] != "r" and color[0] != "b" and color[0] != "g":
        out += s
    return out
# ---------------------------------------------------
def color_tag(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    out = ""
    y0 = s.find('<')
    y1 = s.find('>')
    y2 = s.find('<',y1)
    if s[y0+1] == "r":
        out += red(s[y1+1:y2])
    elif s[y0+1] == "g":
        out += green(s[y1+1:y2])
    elif s[y0+1] == "b":
        out += blue(s[y1+1:y2])
    return out
# ---------------------------------------------------
def highlight_words(s, words):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    for i in range(len(words)):
        if words[i] in s:
            x = s.replace(words[i],highlight(words[i]))
    return x
# ---------------------------------------------------
def display_tag_file(filename):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    file = open(filename, 'r', encoding='utf-8')
    return color_tag(file.read())

6331119721: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display0.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 330, 'const': 394, 'code+const': 724}
def red(s):
  return RED + s + RESET
# ---------------------------------------------------
def green(s):
  return GREEN + s + RESET
# ---------------------------------------------------
def blue(s):
  return BLUE + s + RESET
# ---------------------------------------------------
def highlight(s):
  return HIGHLIGHT + s + RESET
# ---------------------------------------------------
def color_text(s, color):
  lower = color.lower()
  if lower == "red": message = red(s)
  elif lower == "blue": message = blue(s)
  elif lower == "green": message = green(s)
  elif lower == "highlight": message = highlight(s)
  else: message = s
  return message
# ---------------------------------------------------
def color_tag(s):
  s = s.replace("<red>", RED)
  s = s.replace("<blue>", BLUE)
  s = s.replace("<green>", GREEN)
  s = s.replace("</>", RESET)
  return s
# ---------------------------------------------------
def highlight_words(s, words):
  for i in words:
    s = s.replace(i, highlight(i))
  return s
# ---------------------------------------------------
def display_tag_file(filename):
  file = open(filename, 'r', encoding='utf-8')
  return color_tag(file.read())

6331231221: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display0.0FileNotFoundError("No such file or directory: 'มหาจุฬาลงกรณ์-tag.txt'")
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 384, 'const': 754, 'code+const': 1138}
def red(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    w = '\033[;31m' + s + '\033[0m'
    return (w)
# ---------------------------------------------------
def green(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    w = '\033[;32m' + s + '\033[0m'
    return (w)
# ---------------------------------------------------
def blue(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    w = '\033[;34m' + s + '\033[0m'
    return (w)
# ---------------------------------------------------
def highlight(s): 
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    w = '\033[;103m' + s + '\033[0m'
    return (w)
# ---------------------------------------------------
def color_text(s, color): #2
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    color = color.lower()
    #print(color)
    if(color == 'red'):
      return(red(s))
    if(color == 'green'):
      print("I'm here")
      return(green(s))
    if(color == 'blue'):
      return(blue(s))
    return(s)
# ---------------------------------------------------
def color_tag(s): #3
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    if(s[0:5] == '<red>'):
      return(red(s[5:-3]))
    if(s[0:7] == '<green>'):
      return(green(s[7:-3]))
    if(s[0:6] == '<blue>'):
      return(blue(s[6:-3]))
# ---------------------------------------------------
def highlight_words(s, words): #4
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    for i in words:
      s = s.replace(i,highlight(i))
    return s
# ---------------------------------------------------
def display_tag_file(filename): #5
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    f1 = open('มหาจุฬาลงกรณ์-tag.txt', 'r', encoding='utf-8')
    texts = f1.read()  # read the entire file
    f1.close()
    pass

6430064721: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display1.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 658, 'const': 606, 'code+const': 1264}
def red(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    x = RED + s + RESET
    return x
# ---------------------------------------------------
def green(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    x = GREEN + s + RESET
    return x
# ---------------------------------------------------
def blue(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    x = BLUE + s + RESET
    return x
# ---------------------------------------------------
def highlight(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    x = HIGHLIGHT + s + RESET
    return x
# ---------------------------------------------------
def color_text(s, color):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    x = color.lower()
    if x == "red":return red(s)
    elif x == "green":return green(s)
    elif x == "blue":return blue(s)
    else:return s
# ---------------------------------------------------
def color_tag(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    x= s.replace(">","<").split("<")
    if x[1] == "red" :return red(x[2])
    elif x[1] == "green" :return green(x[2])
    elif x[1] == "blue" :return blue(x[2])
    else : return x[2]
# ---------------------------------------------------
def highlight_words(s, words):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    x = s
    for i in words :
        if len(words) != 0: x = x.replace(i,highlight(i))
        else : pass
    return x
# ---------------------------------------------------
def display_tag_file(filename):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    x = open(filename, 'r', encoding='utf-8')
    line = x.readlines()
    show = ""
    for i in line:
        i = i.split("</>")
        for e in i :
            if len(e.split("<red>"))== 2 :
                e = e.split("<red>")
                e[1] = red(e[1])
                e = e[0] + e[1]
                show += e
            elif len(e.split("<green>"))==2 :
                e = e.split("<green>")
                e[1] = green(e[1])
                e = e[0] + e[1]
                show += e
            elif len(e.split("<blue>"))==2 :
                e = e.split("<blue>")
                e[1] = blue(e[1])
                e = e[0] + e[1]
                show += e
            else:show += e
    return print(show)
    x.close

6430071021: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_10.0Illegal imports: ['os']
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0Illegal imports: ['os']
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display0.0Illegal imports: ['os']
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 726, 'const': 643, 'code+const': 1369}
from IPython.core.formatters import JSONFormatter
from os import kill
from re import I
def red(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return RED + s + RESET 
# ---------------------------------------------------
def green(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return  GREEN + s +RESET
# ---------------------------------------------------
def blue(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return  BLUE + s +RESET
# ---------------------------------------------------
def highlight(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return  HIGHLIGHT + s +RESET
# ---------------------------------------------------
def color_text(s, color):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    color = color.upper( )
    if color == 'RED':
      return red(s)
    elif color == 'GREEN':
      return green(s)
    elif color == 'BLUE':
      return blue(s)
    else:
      return s
# ---------------------------------------------------
def color_tag(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    if s[1] == 'r':
      l = s[5::]
      m = l[:-3]
      n = red(m)
    elif s[1] == 'g':
      l = s[7::]
      m = l[:-3]
      n = green(m)    
    elif s[1] == 'b':
      l = s[6::]
      m = l[:-3]
      n = blue(m)
    return n
# ---------------------------------------------------
def highlight_words(s, words):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    for y in words:
      k = ''
      i = 0
      j = 0
      while j >= 0:
        j = s.find(y,i)
        if j == -1:
          break
        k += s[i:j]
        i = j+len(y)
        k += highlight(s[j:j+len(y)])
      k += s[i:len(s)] 
      s = k
    return s
# ---------------------------------------------------
def display_tag_file(filename):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    en = open(filename,'r', encoding='utf-8')
    M = []
    Lie = []
    for k in en:
      M.append(k)
    en.close()
    for b in M:
      zz = ''
      u = 0
      v = 0
      while u >= 0:
        u = b.find('<',v)
        m = b.find('/',v)
        if u == -1:
          break
        zz += b[0:u]
        v = m+2
        j = color_tag(b[u:m+2])
        zz += j
      zz += b[m+2:len(b)]
      b = zz
      print(b)

6430115021: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display0.0FileNotFoundError("No such file or directory: 'มหาจุฬาลงกรณ์-tag.txt.lyrics'")
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 1308, 'const': 1577, 'code+const': 2885}
def red(s):
    r = ""
    r += "\033[;31m"
    r += s
    r += "\033[0m"
    return r
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
# ---------------------------------------------------
def green(s):
    g = ""
    g += "\033[;32m"
    g += s
    g += "\033[0m"
    return g
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
# ---------------------------------------------------
def blue(s):
    b = ""
    b += "\033[;34m"
    b += s
    b += "\033[0m"
    return b
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
# ---------------------------------------------------
def highlight(s):
    h = ""
    h += "\033[;103m"
    h += s
    h += "\033[0m"
    return h
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
# ---------------------------------------------------
def color_text(s, color):
    word = ""
    c = ""
    c += color
    if c.upper() == 'RED' :
        word += "\033[;31m"
        word += s
        word += "\033[0m"
        return word
    elif c.upper() == 'BLUE' :
        word += "\033[;34m"
        word += s
        word += "\033[0m"
        return word
    elif c.upper() == 'GREEN':
        word += "\033[;32m"
        word += s
        word += "\033[0m"
        return word
    else :
        return s
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
# ---------------------------------------------------
def color_tag(s):
    a = ""
    if "<red>" in s :
        i = s.find("<red>")
        j = s.find("<red>",i+1)
        a += RED
        a += s[i+5:j-2]
        a += "\033[0m"
        return a
    elif "<blue>" in s :
        i = s.find("<blue>")
        j = s.find("<blue>",i+1)
        a += BLUE
        a += s[i+6:j-2]
        a += "\033[0m"
        return a
    elif "<green>" in s :
        i = s.find("<green>")
        j = s.find("<green>",i+1)
        a += GREEN
        a += s[i+7:j-2]
        a += "\033[0m"
        return a
    else :
        pass
# ---------------------------------------------------
def highlight_words(s, words):
    t = 'a[3]มิใช่ลิสต์ คืนค่ามิใช่print =มิใช่เปรียบเทียบ รักมิใช่ดวงดาวที่พราวแสง'
    x = ""
    a = s
    for i in range (len(words)):
      if words[i] in s :
          q = s.find(words[i])
          y = ""
          y += s[0:q]
          y += HIGHLIGHT
          y += s[q:q+len(words[i])]
          y += "\033[0m"
          y += s[q+len(words[i]):]
          q = y.find(words[i],q+1+len(HIGHLIGHT)+len("\033[0m"))
          while q != -1 :
              x = ""
              x += y[0:q]
              x += HIGHLIGHT
              x += y[q:q+len(words[i])]
              x += "\033[0m"
              x += y[q+len(words[i]):]
              y = x 
              q = y.find(words[i],q+1+len(HIGHLIGHT)+len("\033[0m"))
      s = y      
    return y                
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
# ---------------------------------------------------
def display_tag_file(filename):
    fn = open('มหาจุฬาลงกรณ์-tag.txt.lyrics', 'r', encoding='utf-8')
    for line in fn :
      if "<red>" in line :
        a = ""
        i = line.find("<red>")
        j = line.find("</>")
        a += line[0:i]
        a += RED
        a += line[i+5:j]
        a += "\033[0m"
        a += line[j+3::]
        print (a)
      if '<blue>' in line :
        a = ""
        i = line.find("<blue>")
        j = line.find("</>")
        a += line[0:i]
        a += BLUE
        a += line[i+6:j]
        a += "\033[0m"
        a += line[j+3::]
        print (a)
      if '<green>' in line :
        a = ""
        i = line.find("<green>")
        j = line.find("</>")
        a += line[0:i]
        a += GREEN
        a += line[i+7:j]
        a += "\033[0m"
        a += line[j+3::]
        print (a)
      else :
        print(line)
    fn.close()
    return fn

6430142021: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display1.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 616, 'const': 492, 'code+const': 1108}
def red(s):
    return (RED+s+RESET)
# ---------------------------------------------------
def green(s):
    return (GREEN+s+RESET)
# ---------------------------------------------------
def blue(s):
    return (BLUE+s+RESET)
# ---------------------------------------------------
def highlight(s):
    return (HIGHLIGHT+s+RESET)
# ---------------------------------------------------
def color_text(s, color):
    if color.lower() == 'red':
        return red(s)
    elif color.lower() == 'green':
        return green(s)
    elif color.lower() == 'blue':
        return blue(s)
    else:
        return s
# ---------------------------------------------------
def color_tag(s):
    list = s.split('>')
    tag = list[0][1:]
    word = list[1][:len(list[1])-2]
    return color_text(word,tag)
# ---------------------------------------------------
def highlight_words(s, words):
    copy = s[:]
    for a in words:
        y = copy.split(a)
        begin = y[0]
        for b in range (1,len(y)):
            begin += HIGHLIGHT + a + RESET + y[b]
        copy = begin[:]
    return copy
# ---------------------------------------------------
def display_tag_file(filename):
    f = open(filename, 'r', encoding='utf-8')
    for line in f:
        line = line.rstrip()
        g = line.split('</>')
        if len(g) == 1:
            print(line)
        elif len(g) == 2:
            k1 = g[0].split('<')
            tag,word = k1[1].split('>')
            print(k1[0] + color_text(word,tag) + g[1])
        else:
            blank = ''
            for a in range (len(g)-1):
                k2 = g[a].split('<')
                tag,word = k2[1].split('>')
                blank += k2[0] + color_text(word,tag)
            blank += g[-1] 
            print(blank)
    f.close()

6430201321: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_10.0
['\x1b[;103ma\x1b[0m\x1b[;103mb\x1b[0m\x1b[;103mc\x1b[0mde\x1b[;103mf\x1b[0m\x1b[;103mg\x1b[0m\x1b[;103ma\x1b[0m\x1b[;103mb\x1b[0m\x1b[;103mc\x1b[0mabbcbf\x1b[;103mf\x1b[0m\x1b[;103mg\x1b[0mcd\x1b[;103ma\x1b[0m\x1b[;103mb\x1b[0m\x1b[;103mc\x1b[0maa\x1b[;103ma\x1b[0m\x1b[;103mb\x1b[0m\x1b[;103mc\x1b[0m']
test_highlight_20.0
['aBCde\x1b[;103mfaBC\x1b[0mde\x1b[;103mfg\x1b[0mAbcAbbcbffGcd\x1b[;103ma\x1Ab[0mc\x1b[;103mAb\x1b[0m\x1b[;103mc\x1b[0maaf\x1b[;103mafG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display0.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 512, 'const': 400, 'code+const': 912}
def red(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return RED + str(s) + RESET
# ---------------------------------------------------
def green(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return GREEN + str(s) + RESET
# ---------------------------------------------------
def blue(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return BLUE + str(s) + RESET
# ---------------------------------------------------
def highlight(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return HIGHLIGHT + str(s) + RESET
# ---------------------------------------------------
def color_text(s, color):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    color_set = [RED,GREEN,BLUE]
    color_word_set = ['red','green','blue']
    if color.lower() in color_word_set:
        return color_set[color_word_set.index(color.lower())] + s + RESET
    else:
        return s
# ---------------------------------------------------
def color_tag(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    c =''
    while '</>' in s :
        c += s[:s.find('<')]
        color = s[s.find('<')+1:s.find('>')]
        n = s[s.find('>')+1:s.find('</>')]
        c += color_text(n, color)
        s = s[s.find('</>') + 3:]
    return c + s
# ---------------------------------------------------
def highlight_words(s, words):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    a = list(s)
    b = list(s)
    for i in words:
        while i in s:
            start = s.find(i)
            stop = start + len(i)
            for h in range(start,stop):
                a[h] = highlight(a[h])
                b[h] = ' '
            s = ''.join(b)
    return ''.join(a)
# ---------------------------------------------------
def display_tag_file(filename):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    n = ''
    file = open(filename, "r")
    for line in file:
        n += color_tag(line)
    file.close()
    return n

6430206521: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0
['\x1b[;103mabcBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103maAbc\x1b[0mAbbcbf\x1b[;103mfgG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display0.0FileNotFoundError("No such file or directory: 'มหาจุฬาลงกรณ์-tag.txt'")
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 570, 'const': 518, 'code+const': 1088}
def red(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return RED+s+RESET
# ---------------------------------------------------
def green(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return GREEN+s+RESET
# ---------------------------------------------------
def blue(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return BLUE+s+RESET
# ---------------------------------------------------
def highlight(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return HIGHLIGHT+s+RESET
# ---------------------------------------------------
def color_text(s, color):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    color = color.lower()
    if color == 'red':
        return red(s)
    elif color == 'blue':
        return blue(s)
    elif color == 'green':
        return green(s)
    else:
        return s
# ---------------------------------------------------
def color_tag(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    tags =['<red>','<green>','<blue>','</>']
    escs =[RED,GREEN,BLUE,RESET]
    for i in range(len(tags)):
        tag = tags[i]
        esc = escs[i]
        d=[]
        k0=0
        k= s.find(tag,k0)
        while k >= 0:
            a=s[k0:k]
            d.append(a)
            d.append(esc)
            k0 = k+len(tag)
            k= s.find(tag,k0)
        d.append(s[k0:])
        s=''.join(d)
    return s
# ---------------------------------------------------
def highlight_words(s, words):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    for word in words:
        word = word.lower()
        d=[]
        k0=0
        k=s.lower().find(word,k0)
        while k >= 0:
            a=s[k0:k]
            d.append(a)
            d.append(HIGHLIGHT)
            d.append(word)
            d.append(RESET)
            k0=k+len(word)
            k=s.lower().find(word,k0)
        d.append(s[k0:])
        s=''.join(d)
    return s
# ---------------------------------------------------
def display_tag_file(filename):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    f=open('มหาจุฬาลงกรณ์-tag.txt', 'r', encoding='utf-8')
    txt = f.read()
    print(color_tag(txt))

6430224821: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display0.0FileNotFoundError("No such file or directory: 'มหาจุฬาลงกรณ์-tag.txt'")
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 464, 'const': 991, 'code+const': 1455}
def red(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return '\033[;31m'+s+'\033[0m'
# ---------------------------------------------------
def green(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return '\033[;32m'+s+'\033[0m'
# ---------------------------------------------------
def blue(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return '\033[;34m'+s+'\033[0m'
# ---------------------------------------------------
def highlight(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return '\033[;103m'+s+'\033[0m'
# ---------------------------------------------------
def color_text(s, color):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    bn = ['red','green','blue']
    es = color.lower()
    if es == bn[0]:
        return red(s)
    if es == bn[1]:
        return green(s)
    if es == bn[2]:
        return blue(s)
    else:
        return s
# ---------------------------------------------------
def color_tag(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    if s[1] == 'r':
        return red(s[5:-3:])
    if s[1] == 'g':
        return green(s[7:-3:])
    if s[1] == 'b':
        return blue(s[6:-3:])
# ---------------------------------------------------
def highlight_words(s, words):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    for i in words:
        s = s.replace(i,highlight(i))
    return s
# ---------------------------------------------------
def display_tag_file(filename):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
  es = open('มหาจุฬาลงกรณ์-tag.txt', 'r', encoding='utf-8')
  for line in es:
    if '<red>' in line:
      line = line.replace('<red>','\033[;31m')
    if '<green>' in line:
      line = line.replace('<green>','\033[;32m')
    if '<blue>' in line:
      line = line.replace('<blue>','\033[;34m')
    if '</>' in line:
      line = line.replace('</>','\033[0m')
    print(line)
  es.close()

6430303721: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display1.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 450, 'const': 738, 'code+const': 1188}
def red(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return  '\033[;31m' + s  + '\033[0m'
# ---------------------------------------------------
def green(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return  '\033[;32m' + s  + '\033[0m'
# ---------------------------------------------------
def blue(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return  '\033[;34m' + s  + '\033[0m'
# ---------------------------------------------------
def highlight(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return  '\033[;103m' + s  + '\033[0m'
# ---------------------------------------------------
def color_text(s, color):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    x = color.lower()
    if x == 'red' :
        return red(s)
    elif x == 'green' :
        return green(s)
    elif x == 'blue' :
        return blue(s)
    else :
        return '\033[0m' + s
# ---------------------------------------------------
def color_tag(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    n1 = s.find('<')
    n2 = s.find('>', n1+1)
    color = s[n1+1:n2]
    text = s[n2+1:s.find('</>')]
    return color_text(text, color)
# ---------------------------------------------------
def highlight_words(s, words):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    for word in words:
        if s.find(word) != -1:
            s = s.replace(word, highlight(word))
    return s
# ---------------------------------------------------
def display_tag_file(filename):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    f = open(filename, 'r', encoding='utf-8')
    text = f.readlines()
    for line in text:
      line = line.replace('\n', '')
      count = line.count('</>')
      for i in range(count):
        word = line[line.find('<'): line.find('</>')+3]
        new = color_tag(word)
        line = line.replace(word, new)
      print(line)
    return

6430313021: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display0.0FileNotFoundError("No such file or directory: 'มหาจุฬาลงกรณ์-tag.txt'")
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 438, 'const': 464, 'code+const': 902}
def red(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return RED + s + RESET
# ---------------------------------------------------
def green(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return GREEN + s + RESET
# ---------------------------------------------------
def blue(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return BLUE + s + RESET
# ---------------------------------------------------
def highlight(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return HIGHLIGHT + s + RESET
# ---------------------------------------------------
def color_text(s, color):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    if color.lower() == "red":
        return red(s)
    elif color.lower() == "green":
        return green(s)
    elif color.lower() == "blue":
        return blue(s)
    else:
        return s
# ---------------------------------------------------
def color_tag(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    ข้อความ = ""
    ข้างใน = False
    สี = ""
    คำตอบ = ""
    for ch in s:
        if ch == '<':
            ข้างใน = True
            continue
        elif ch == '>':
            ข้างใน = False
            continue
        elif ข้างใน:
            สี += ch
        if สี:
            if not ข้างใน : 
                ข้อความ += ch
            if สี[-1] == "/":
                คำตอบ += color_text(ข้อความ, สี[:-1])
                ข้อความ = ""
                สี = ""
        else :
            คำตอบ += ch
    return คำตอบ
# ---------------------------------------------------
def highlight_words(s, words):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    คำตอบ = s
    for e in words:
        เอาออก = คำตอบ.split(e)
        คำตอบ = highlight(e).join(เอาออก)
    return คำตอบ
# ---------------------------------------------------
def display_tag_file(filename):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    with open('มหาจุฬาลงกรณ์-tag.txt', 'r', encoding='utf-8') as ข้างใน:
        ข้อมูล = ข้างใน.read()
    print(color_tag(ข้อมูล))

6430314621: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display0.0FileNotFoundError("No such file or directory: 'มหาจุฬาลงกรณ์-tag.txt'")
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 804, 'const': 781, 'code+const': 1585}
def red(s):
    return RED+str(s)+RESET
# ---------------------------------------------------
def green(s):
    return GREEN+str(s)+RESET
# ---------------------------------------------------
def blue(s):
    return BLUE+str(s)+RESET
# ---------------------------------------------------
def highlight(s):
    return HIGHLIGHT+str(s)+RESET
# ---------------------------------------------------
def color_text(s, color):
    color=color.lower()
    if color=='red':
        return red('\033[;40m'+str(s))
    elif color=='green':
        return (green('\033[;40m'+str(s)))
    elif color=='blue':
        return ('\033[;40m'+blue(s))
    else:
        return ('\033[;37m'+'\033[;40m'+s+RESET)
# ---------------------------------------------------
def color_tag(s):
    x=s.replace('</>','' )
    if '<red>' in s:
        y=x.replace('<red>','')
        return '\033[;40m'+red(y)
    elif'<green>' in s:
        y=x.replace('<green>','')
        return '\033[;40m'+green(y)
    elif '<blue>' in s:
        y=x.replace('<blue>','')
        return '\033[;40m'+blue(y)
# ---------------------------------------------------
def highlight_words(s, words):
    for e in words:
        x=s.split(e)
        answer=''
        for f in range(len(x)):
            answer+=x[f]
            if not f==len(x)-1:
                answer+=highlight(e)
        s=answer.lstrip()   
    return s
# ---------------------------------------------------
def display_tag_file(filename):
    song=open('มหาจุฬาลงกรณ์-tag.txt', 'r', encoding='utf-8')
    for line in song:
        new_line=line
        if len(line)==0:
            break
        if '<red>' in new_line:
            start=new_line.find('<red>')
            finish=new_line.find('</>')
            change=new_line[start:finish]
            change=change.replace('<red>','')
            change=red(change)
            new_line= new_line[:start]+change+new_line[finish+3:]
        if '<blue>' in new_line:
            start=new_line.find('<blue>')
            finish=new_line.find('</>')
            change=new_line[start:finish]
            change=change.replace('<blue>','')
            change=blue(change)
            new_line= new_line[:start]+change+new_line[finish+3:]
        if '<green>' in new_line:
            start=new_line.find('<green>')
            finish=new_line.find('</>')
            change=new_line[start:finish]
            change=change.replace('<green>','')
            change=green(change)
            new_line= new_line[:start]+change+new_line[finish+3:]
        print(new_line)
    song.close()

6430322621: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display0.0
abcrrrpkk

defgggocr

xyzbbbabc

abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 346, 'const': 360, 'code+const': 706}
def red(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return RED+str(s)+RESET
# ---------------------------------------------------
def green(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return GREEN+str(s)+RESET
# ---------------------------------------------------
def blue(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return BLUE+str(s)+RESET
# ---------------------------------------------------
def highlight(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
     return HIGHLIGHT+str(s)+RESET
# ---------------------------------------------------
def color_text(s, color):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    if color.lower()=='red':
      return red(s)
    elif color.lower()=='green':
      return green(s)
    elif color.lower()=='blue':
      return blue(s)
    else:
      return s
# ---------------------------------------------------
def color_tag(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    s = s.replace('<red>',RED)
    s = s.replace('<green>',GREEN)
    s = s.replace('<blue>',BLUE)
    s = s.replace('</>',RESET)
    return s
# ---------------------------------------------------
def highlight_words(s, words):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    for i in words:
      s = s.replace(i,HIGHLIGHT+i+RESET)
    return s
# ---------------------------------------------------
def display_tag_file(filename):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    infile = open(filename, 'r', encoding='utf-8')
    for line in infile:
      print(color_tag(line))
    infile.close()

6430328421: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display0.0FileNotFoundError("No such file or directory: 'มหาจุฬาลงกรณ์-tag.txt'")
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 500, 'const': 861, 'code+const': 1361}
def red(s):
    a='\033[;31m'+s+'\033[0m'
    return a
# ---------------------------------------------------
def green(s):
    a='\033[;32m'+s+'\033[0m'
    return a
# ---------------------------------------------------
def blue(s):
    a='\033[;34m'+s+'\033[0m'
    return a
# ---------------------------------------------------
def highlight(s):
    a='\033[;103m'+s+'\033[0m'
    return a
# ---------------------------------------------------
def color_text(s, color):
    color_low = color.lower()
    if color_low == 'red':
        a=red(s)
    if color_low == 'green':
        a=green(s)
    if color_low == 'blue':
        a=blue(s)
    if color_low != 'red' and color_low != 'green' and color_low != 'blue':
        a=s
    return a
# ---------------------------------------------------
def color_tag(s):
    if s[1]=='r':
        a=s[5:-3]
        b=color_text(a,'red')
    if s[1]=='g':
        a=s[7:-3]
        b=color_text(a,'green')
    if s[1]=='b':
        a=s[6:-3]
        b=color_text(a,'blue')
    return b
# ---------------------------------------------------
def highlight_words(s, words):
    for c in words :
        b=highlight(c)
        s=s.replace(c,b)
    return s
# ---------------------------------------------------
def display_tag_file(filename):
    fin=open('มหาจุฬาลงกรณ์-tag.txt', 'r', encoding='utf-8')
    for line in fin:
        z=line.count('/')
        for i in range (z):
            a=line.index('<')
            b=line.index('/')
            c=line[a:b+2]
            line=line.replace(c,color_tag(c))
        print(line)
    fin.close()

6430363321: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display0.0
abcrrrpkk

defgggocr

xyzbbbabc

abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 614, 'const': 897, 'code+const': 1511}
def red(s):
    a = '\033[;31m' + s + '\033[0m'
    return a 
# ---------------------------------------------------
def green(s):
    r = '\033[;32m' + s + '\033[0m'
    return r
# ---------------------------------------------------
def blue(s):
    r = '\033[;34m' + s + '\033[0m'
    return r
# ---------------------------------------------------
def highlight(s):
    r = '\033[;103m' + s + '\033[0m'
    return r
# ---------------------------------------------------
def color_text(s, color):
    color = color.lower()
    if color == 'red':
        a = red(s)
        return a
    else:
        if color == 'green':
            a = green(s)
            return a
        else:
            if color == 'blue':
                a = blue(s)
                return a
            else:
                return s
# ---------------------------------------------------
def color_tag(s):
    if '<red>' in s:
        a = red(s)
        a = a.replace('<red>','')
    else:
        if '<blue>' in s:
            a = blue(s)
            a = a.replace('<blue>','')
        else:
            if '<green>' in s:
                a = green(s)
                a = a.replace('<green>','')
    a = a.replace('</>','')    
    return a
# ---------------------------------------------------
def highlight_words(s, words):
    new_s = s.lower()
    new_w = []
    for q in words:
        new_w.append(q.lower())
    ind = []
    for o in new_w:
        ind.append([new_s.find(o),len(o)])
    new_word = []
    for t in ind:
        wo = s[t[0]:t[0]+t[1]:1]
        new_word.append(wo)
    b = s
    for a in new_word:
        b = b.replace(a,highlight(a))
    return b
# ---------------------------------------------------
def display_tag_file(filename):
    f = open(filename, 'r', encoding='utf-8')
    a = []
    for line in f:
        a.append(line)
    f.close()
    for i in a:
        re = i
        re = re.replace("<red>", "\033[;31m")
        re = re.replace("<blue>", "\033[;34m")
        re = re.replace("<green>", "\033[;32m")
        re = re.replace("</>", "\033[0m")
        print(re)

6430382221: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display1.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 488, 'const': 665, 'code+const': 1153}
def red(s):
    r = '\033[;31m'+s+'\033[0m'
    return r
# ---------------------------------------------------
def green(s):
    g = '\033[;32m'+s+'\033[0m'
    return g
# ---------------------------------------------------
def blue(s):
    b = '\033[;34m'+s+'\033[0m'
    return b
# ---------------------------------------------------
def highlight(s):
    h = '\033[;103m'+s+'\033[0m'
    return h
# ---------------------------------------------------
def color_text(s, color):
    l = color.lower()
    if l =='red':
        return red(s)
    if l =='green':
        return green(s)
    if l =='blue':
        return blue(s)
    else:
        return s
# ---------------------------------------------------
def color_tag(s):
    c = s.replace(' ','$')
    a = c.replace('<', ' ')
    b = a.replace('>', ' ')
    eat = b.split()
    sexy =[]
    for i in range(len(eat)):
        if eat[i] =='/':
            eat[i-1] = color_text(eat[i-1],eat[i-2])
            sexy.append(eat[i-2])
            sexy.append(eat[i])
    for i in sexy:
        eat.remove(i)
    poop = ''.join(eat)
    poop = poop.replace('$',' ') 
    return poop
# ---------------------------------------------------
def highlight_words(s, words):
    for i in words:
        s = s.replace(i,highlight(i))
    return s
# ---------------------------------------------------
def display_tag_file(filename):
    f = open(filename, 'r', encoding='utf-8')
    for line in f:
        line = color_tag(line)
        print(line)
    f.close()

6430402121: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display0.0FileNotFoundError("No such file or directory: 'มหาจุฬาลงกรณ์-tag.txt'")
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 514, 'const': 505, 'code+const': 1019}
def red(s):
    return RED + s + RESET
# ---------------------------------------------------
def green(s):
    return GREEN + s + RESET
# ---------------------------------------------------
def blue(s):
    return BLUE + s + RESET
# ---------------------------------------------------
def highlight(s):
    return HIGHLIGHT + s + RESET
# ---------------------------------------------------
def color_text(s, color):
    if color.upper() == 'RED':
        return RED + s + RESET
    elif color.upper() == 'GREEN':
        return GREEN + s + RESET
    elif color.upper() == 'BLUE':
        return BLUE + s + RESET
    else:return s
# ---------------------------------------------------
def color_tag(s):
    x = ''
    color = ''
    ans = ''
    n = len(s)
    i = 0
    while i < n:
        if s[i] == '<':
            while s[i+1] != '>':
                i += 1
                color += s[i]
            if color[-1] != "/":
                i += 2
            else:
                ans += color_text(x, color[:-1])
                x = ''
                color = ''
                i += 2
            if i >= n: break
        if color:
            x += s[i]
        else:
            ans += s[i]
        i += 1
    return ans[:]
# ---------------------------------------------------
def highlight_words(s, words):
    x = s
    for e in words:
        y = x.split(e)
        x = highlight(e).join(y) #แทนcomma
    return x
# ---------------------------------------------------
def display_tag_file(filename):
    InFile = open('มหาจุฬาลงกรณ์-tag.txt', 'r', encoding='utf-8')
    t = ""
    for line in InFile:
        t += line
    InFile.close()
    print(color_tag(t))
# display_tag_file('มหาจุฬาลงกรณ์-tag.txt')

6430450221: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display0.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 436, 'const': 304, 'code+const': 740}
def red(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return RED+s+RESET
# ---------------------------------------------------
def green(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return GREEN+s+RESET
# ---------------------------------------------------
def blue(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return BLUE+s+RESET 
# ---------------------------------------------------
def highlight(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return HIGHLIGHT+s+RESET
# ---------------------------------------------------
def color_text(s, color):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    color=color.lower()
    if color=='red':
        return red(s)
    elif color=='green':
        return green(s)
    else:
        return blue(s)
# ---------------------------------------------------
def color_tag(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    if s[0:5]=='<red>':
        k=s[5:-3]
        return red(k)
    elif s[0:5]=='<green>':
        k=s[5:-3]
        return green(k)
    elif s[0:5]=='<blue>':
        k=s[5:-3]
        return blue(k)
# ---------------------------------------------------
def highlight_words(s, words):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    q=''
    for i in range(len(words)):
        l=s.find(words[i])
        while l!=-1:
            q+=s[:l]+highlight(words[i])
            s=s[l+len(words[i]):]
            l=s.find(words[i])
        q+=s
        s=q
        q=''
    return s
# ---------------------------------------------------
def display_tag_file(filename):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    pass

6431007121: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display1.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 538, 'const': 443, 'code+const': 981}
def red(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return RED + s + RESET
# ---------------------------------------------------
def green(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return GREEN + s + RESET
# ---------------------------------------------------
def blue(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return BLUE + s + RESET
# ---------------------------------------------------
def highlight(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return HIGHLIGHT + s + RESET
# ---------------------------------------------------
def color_text(s, color):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    color = color.lower()
    out = ""
    if color == "red":
        out = red(s)
    elif color == "green":
        out = green(s)
    elif color == "blue":
        out = blue(s)
    else:
        out = s
    return out
# ---------------------------------------------------
def color_tag(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    while "<red>" in s:
        start = s.find("<red>")
        stop = s.find("</>", start)
        s = s[:start] + red(s[start + 5:stop]) + s[stop + 3:]
    while "<green>" in s:
        start = s.find("<green>")
        stop = s.find("</>", start)
        s = s[:start] + green(s[start + 7:stop]) + s[stop + 3:]
    while "<blue>" in s:
        start = s.find("<blue>")
        stop = s.find("</>", start)
        s = s[:start] + blue(s[start + 6:stop]) + s[stop + 3:]
    return s
# ---------------------------------------------------
def highlight_words(s, words):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    for w in words:
        s = s.replace(w, highlight(w))
    return s
# ---------------------------------------------------
def display_tag_file(filename):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    f = open(filename, "r", encoding="utf-8")
    txt = f.read()
    txt = color_tag(txt)
    print(txt)
    f.close()

6431013921: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display0.0AttributeError("'str' object has no attribute 'close'")
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 648, 'const': 955, 'code+const': 1603}
def red(s):
    s = str(s)
    return ('\033[;31m' + s + '\033[0m')
# ---------------------------------------------------
def green(s):
    s = str(s)
    return ('\033[;32m' + s + '\033[0m')
# ---------------------------------------------------
def blue(s):
    s = str(s)
    return ('\033[;34m' + s + '\033[0m')
# ---------------------------------------------------
def highlight(s):
    s = str(s)
    return ('\033[;103m' + s + '\033[0m')
# ---------------------------------------------------
def color_text(s, color):
    s = str(s)
    color = str(color).lower()
    if color == "red":
        return red(s)
    if color == "green":
        return green(s)
    if color == "blue":
        return blue(s)
    else:
        return s
# ---------------------------------------------------
def color_tag(s):
    s = str(s)
    tempchar = ""
    result = ""
    for char in s:
        tempchar += char
        if tempchar == "<red>":
            tempchar = ""
            return red(s[5:-3])
            break
        if tempchar == "<blue>":
            tempchar = ""
            return blue(s[6:-3])
            break
        if tempchar == "<green>":
            tempchar = ""
            return green(s[7:-3])    
# ---------------------------------------------------
def highlight_words(s, words):
    t = str(s)
    words = [str(elem) for elem in words]
    for word in words:
        if word in s:
            t = t.replace(word, highlight(word))
    return t
# ---------------------------------------------------
def display_tag_file(filename):
    f = open(filename, 'r', encoding = 'utf-8')
    f = f.read()
    f = str(f)
    f = f.replace("<red>", "~<red>")
    f = f.replace("<green>", "~<green>")
    f = f.replace("<blue>", "~<blue>")
    f = f.replace("</>", "</>~")
    x = f.split("~")
    temp = []
    stri = ""
    for elem in x:
        if "<red>" in elem or "<green>" in elem or "<blue>" in elem:
            temp.append(color_tag(elem))
        else:
            temp.append(elem)
    for elem in temp:
        stri += elem
    f.close()
    return stri

6431017421: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_10.0
['\x1b[30;103mabc\x1b[0mde\x1b[30;103mfg\x1b[0m\x1b[30;103mabc\x1b[0mabbcbf\x1b[30;103mfg\x1b[0mcd\x1b[30;103mabc\x1b[0maa\x1b[30;103mabc\x1b[0m']
test_highlight_20.0
['\x1b[;103maBC\x1b[0mde\x1b[30;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[30;103mabc\x1b[0maa\x1b[30;103mabc\x1b[0m']
test_display1.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 562, 'const': 517, 'code+const': 1079}
def red(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return RED + s + RESET
# ---------------------------------------------------
def green(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return GREEN + s + RESET
# ---------------------------------------------------
def blue(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return BLUE + s + RESET
# ---------------------------------------------------
def highlight(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    highlight = '\033[30;103m'
    return highlight + s + RESET
# ---------------------------------------------------
def color_text(s, color):
    ansi = RESET
    color = color.lower()
    if color == 'red':
      ansi = RED
    elif color == 'green':
      ansi = GREEN
    elif color == 'blue':
      ansi = BLUE
    return ansi + s + RESET
# ---------------------------------------------------
def color_tag(s):
    string = ''
    tag = ''
    for c in s:
      if c == '>' and len(tag)>0:
        tag += c
        if tag[1:-1] == 'red':
          string += RED
        elif tag[1:-1] == 'green':
          string += GREEN
        elif tag[1:-1] == 'blue':
          string += BLUE
        elif tag[1:-1] == '/':
          string += RESET
        tag = ''
      elif c == '<' or len(tag)>0:
        tag += c
      else:
        string += c
    return string
# ---------------------------------------------------
def highlight_words(s, words):
    copy_s = s
    for word in words:
      skip = 0
      found = copy_s.count(word)
      for i in range(found):
        word_start_index = skip + copy_s[skip:].find(word)
        word_end_index = word_start_index + len(word)
        copy_s = copy_s[:word_start_index] + highlight(word) + copy_s[word_end_index:]
        skip = len(copy_s[:word_start_index] + highlight(word))
    return copy_s
# ---------------------------------------------------
def display_tag_file(filename):
    f = open(filename, 'r', encoding='utf-8')
    content = f.read()
    print(color_tag(content))

6431025421: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_10.0EOFError('EOF when reading a line')
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0EOFError('EOF when reading a line')
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display0.0FileNotFoundError("No such file or directory: 'มหาจุฬาลงกรณ์-tag.txt'")
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 512, 'const': 1333, 'code+const': 1845}
def red(s):
    c = '\033[;31m' + s + '\033[0m'
    return c
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
# ---------------------------------------------------
def green(s):
    d = '\033[;32m' + s + '\033[0m'
    return d
# ---------------------------------------------------
def blue(s):
    e = '\033[;34m' + s  + '\033[0m'
    return e
# ---------------------------------------------------
def highlight(s):
    f = '\033[;103m' + s + '\033[0m'
    return f
# ---------------------------------------------------
def color_text(s, color):
    if color == 'red':
       g = '\033[;31m' + s + '\033[0m'
    if color == 'GreeN':
       g = '\033[;32m' + s + '\033[0m'
    if color == 'BLUE':
       g = '\033[;34m' + s  + '\033[0m'
    else:
       g = s
    return g
# ---------------------------------------------------
def color_tag(s):
    a = '<red>'
    cc = '<green>'
    dd = '<blue>'
    b = '</>'
    if (s == a + 'red text' + b):
       g1 = '\033[;31m' + 'red text' + '\033[0m'
       return g1
    if (s == cc + 'green text' + b):
       g2 = '\033[;32m' + 'green text' + '\033[0m'
       return g2
    if (s == dd + 'blue text' + b):
       g3 = '\033[;34m' + 'blue text' + '\033[0m'
       return g3
# ---------------------------------------------------
def highlight_words(s, words):
    words = []
    t = input()
    pass
# ---------------------------------------------------
def display_tag_file(filename):
    op = open('มหาจุฬาลงกรณ์-tag.txt', 'r', encoding='utf-8')
    read = op.read()
    r2 = read.split('</>')
    r5 = ''
    for e in r2:
        if '<red>' in e:
            r3 = e.split('<red>')
            r4 = '\033[;31m' + r3[1] + '\033[0m'
            r5 += r3[0] + r4
        if '<blue>' in e:
            r6 = e.split('<blue>')
            r7 = '\033[;34m' + r6[1] + '\033[0m'
            r5 += r6[0] + r7
        if '<green>' in e:
            r8 = e.split('<green>')
            r9 = '\033[;32m' + r8[1] + '\033[0m'
            r5 += r3[0] + r9
    return print(r5)

6431027721: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display0.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 684, 'const': 572, 'code+const': 1256}
def red(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return RED+str(s)+RESET
# ---------------------------------------------------
def green(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return GREEN+str(s)+RESET
# ---------------------------------------------------
def blue(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return BLUE+str(s)+RESET
# ---------------------------------------------------
def highlight(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return HIGHLIGHT+str(s)+RESET
def color_text(s, color):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    if color.upper() == 'RED':
        return red(s)
    elif color.upper() == 'BLUE':
        return blue(s)
    elif color.upper() == 'GREEN':
        return green(s)
    else:
        return RESET+str(s)+RESET
# ---------------------------------------------------
def color_tag(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    a = s.split('</>')
    if '<red>' in a[0]:
        a = a[0].split('<red>')
        return red(a[1])
    elif '<blue>' in a[0]:
        a = a[0].split('<blue>')
        return blue(a[1])
    elif '<green>' in a[0]:
        a = a[0].split('<green>')
        return green(a[1])
# ---------------------------------------------------
def highlight_words(s, words):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    c = 0
    for i in range(len(words)):
        if words[i] in s:
            s = s.split(words[i])
            text = (highlight(words[i]).join(s))
            s = text
            c+=1
    if c>0:
        return text
    else: return s
# ---------------------------------------------------
def display_tag_file(filename):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    file = open(filename, 'r', encoding='utf-8')
    text = file.read()
    text_use = text.split('</>')
    for i in range(len(text_use)):
        if '<red>' in text_use[i] or '<blue>' in text_use[i] or '<green>' in text_use[i]:
            color = color_tag(text_use[i]+'</>')
            if '<red>' in text_use[i]:
                text_x = text_use[i].split('<red>')
            elif '<blue>' in text_use[i]:
                text_x = text_use[i].split('<blue>')
            elif '<green>' in text_use[i]:
                text_x = text_use[i].split('<green>')
            text_use[i] = text_x[0]+color+''
    file.close()
    return ("".join(text_use))

6431103721: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_10.0
[Non'\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0
[Non'\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display0.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 276, 'const': 227, 'code+const': 503}
def red(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return RED + str(s) + RESET
# ---------------------------------------------------
def green(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return GREEN + str(s) + RESET
# ---------------------------------------------------
def blue(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return BLUE + str(s) + RESET
# ---------------------------------------------------
def highlight(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return HIGHLIGHT + str(s) + RESET
# ---------------------------------------------------
def color_text(s, color):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    if color.upper() == "RED" :
      return red(s)
    if color.upper() == "GREEN" :
      return green(s)
    if color.upper() == "BLUE" :
      return blue(s)
    else:
      return s 
    # ---------------------------------------------------
def color_tag(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    color,text = s.split(">")[:-1]
    color = color[1:]
    text = text[:-2]
    return color_text(text, color)
# ---------------------------------------------------
def highlight_words(s, words):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    pass
# ---------------------------------------------------
def display_tag_file(filename):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    pass

6431105021: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_10.0
['\x1b[;103m\x1b[;103mabc\x1b[0m\x1b[0mde\x1b[;103m\x1b[;103mfg\x1b[0m\x1b[0m\x1b[;103m\x1b[;103mabc\x1b[0m\x1b[0mabbcbf\x1b[;103m\x1b[;103mfg\x1b[0m\x1b[0mcd\x1b[;103m\x1b[;103mabc\x1b[0m\x1b[0maa\x1b[;103m\x1b[;103mabc\x1b[0m\x1b[0m']
test_highlight_20.0
['aBCde\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbffGcd\x1b[;103mfG\x1b[;103mabcd\x1b[;103mabc\x1b[0maa\x1b[;103m\x1b[;103mabc\x1b[0m\x1b[0m']
test_display1.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 740, 'const': 900, 'code+const': 1640}
def red(s):
    x = '\033[;31m'+s+'\033[0m'
    return x
# ---------------------------------------------------
def green(s):
    x = '\033[;32m'+s+'\033[0m'
    return x
# ---------------------------------------------------
def blue(s):
    x = '\033[;34m'+s+'\033[0m'
    return x
# ---------------------------------------------------
def highlight(s):
    x = '\033[;103m'+s+'\033[0m'
    return x
# ---------------------------------------------------
def color_text(s, color):
    x = s
    if len(color) == 3:
        x = red(s)
    if len(color) == 5:
        x = green(s)
    if len(color) == 4:
        x = blue(s)
    return x
# ---------------------------------------------------
def color_tag(s):
    color = ''
    for i in s:
        if i =='>':
            break
        else:
            color += i
    if len(color) == 4:
        x = red(s[len(color)+1:-3])
    if len(color) == 6:
        x = green(s[len(color)+1:-3])
    if len(color) == 5:
        x = blue(s[len(color)+1:-3])
    return x
# ---------------------------------------------------
def highlight_words(s, words):
    new_word = s
    if words == []:
        return s
    else:
        for i in words:
            new_word = new_word.replace(i,highlight(i))
            new_word = new_word.replace(i.lower(),highlight(i.lower()))
            new_word = new_word.replace(i.upper(),highlight(i.upper()))
        return new_word
# ---------------------------------------------------
def display_tag_file(filename):
    file = open(filename, 'r', encoding='utf-8')
    read_file = file.read()
    s = read_file.split('</>')   
    n = 0
    for i in s:
        if ('<' in i) and ('>' in i):
            k = i[i.index('<'):]
            v = i[i.index('>')+1:] 
            if 'red' in k:
                s[n] = s[n].replace(k,'\033[;31m'+v+'\033[0m')
            elif 'blue' in k:
                s[n] = s[n].replace(k,'\033[;34m'+v+'\033[0m')
            elif 'green' in k:
                s[n] = s[n].replace(k,'\033[;32m'+v+'\033[0m')
            else:
                s[n] = s[n].replace(k,v)
        n += 1
    word_color = ''
    for e in s:
        word_color += e
    return print(word_color)

6431112321: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display0.0
abcrrrpkk

defgggocr

xyzbbbabc

abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 504, 'const': 1006, 'code+const': 1510}
def red(s):
    return '\033[;31m' + str(s) + '\033[0m'
# ---------------------------------------------------
def green(s):
    return '\033[;32m' + str(s) + '\033[0m'
# ---------------------------------------------------
def blue(s):
    return '\033[;34m' + str(s) + '\033[0m'
# ---------------------------------------------------
def highlight(s):
    return '\033[;103m' + str(s) + '\033[0m'
# ---------------------------------------------------
def color_text(s, color):
    color = str(color)
    if color.lower() == 'red' :
        return '\033[;31m' + str(s) + '\033[0m'
    elif color.lower() == 'green' :
        return '\033[;32m' + str(s) + '\033[0m'
    elif color.lower() == 'blue' :
        return '\033[;34m' + str(s) + '\033[0m'
    else :
        return str(s)   
# ---------------------------------------------------
def color_tag(s):
    s = str(s)
    if s.find('<red>') >= 0 :
        return red(s[5:-3])
    if s.find('<green>') >= 0 :
        return green(s[7:-3])
    if s.find('<blue>') >= 0 :
        return blue(s[6:-3])
# ---------------------------------------------------
def highlight_words(s, words):
    s = str(s)
    if words == [] :
        return s
    else :
        for i in range(len(words)):
            s = s.replace(words[i],highlight(words[i]))
        return s
# ---------------------------------------------------
def display_tag_file(filename):
    file = open(filename, 'r', encoding='utf-8')
    for i in file :
        x = i.replace('<red>','\033[;31m').replace('<green>','\033[;32m').replace('<blue>','\033[;34m').replace('</>','\033[0m')
        print(str(x))
    file.close()

6431120321: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display0.0
abcrrrpkk

defgggocr

xyzbbbabc

abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 504, 'const': 836, 'code+const': 1340}
def red(s):
    return '\033[;31m'+ s + '\033[0m'
# ---------------------------------------------------
def green(s):
    return '\033[;32m'+ s + '\033[0m'
# ---------------------------------------------------
def blue(s):
    return '\033[;34m'+ s + '\033[0m'
# ---------------------------------------------------
def highlight(s):
    return '\033[;103m'+ s + '\033[0m'
# ---------------------------------------------------
def color_text(s, color):
    if color.lower() in ['red','green','blue']:
        if color.lower() == 'red':
            return '\033[;31m'+ s + '\033[0m'
        if color.lower() == 'green':
            return '\033[;32m'+ s + '\033[0m'
        if color.lower() == 'blue':
            return '\033[;34m'+ s + '\033[0m'
    else :
        return s
# ---------------------------------------------------
def color_tag(s):
    return color_text(s[ s.find('>') +1: s.find('</>') ], s[ s.find('<') +1: s.find('>') ])
# ---------------------------------------------------
def highlight_words(s, words):
    for i in words:
        if i in s:
            s = s.replace(i,highlight(i))
    return s
# ---------------------------------------------------
def display_tag_file(filename):
    fin = open(filename, 'r', encoding='utf-8')
    for i in fin:
        c = i.count('</>')
        n = 0
        C = 0
        x = i
        while n != c :
            I = x[x.find('<',C): x.find('</>',C)+3]
            x = x[0:x.find('<',C)] + color_tag(I) + x[x.find('</>',C)+3:-1] + x[-1]
            n += 1
            C = x.find('<')
        print(x)
    fin.close()
# ---------------------------------------------------

6431133521: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display0.0FileNotFoundError("No such file or directory: 'filename'")
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 532, 'const': 790, 'code+const': 1322}
from pickle import NEWOBJ
def red(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    New = '\033[;31m' + str(s) + '\033[0m'
    return New
# ---------------------------------------------------
def green(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    New = '\033[;32m' + str(s) + '\033[0m'
    return New
# ---------------------------------------------------
def blue(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    New = '\033[;34m' + str(s) + '\033[0m'
    return New
# ---------------------------------------------------
def highlight(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    New = '\033[;103m' + str(s) + '\033[0m'
    return New
# ---------------------------------------------------
def color_text(s, color):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    color = color.lower()
    if color == "red":
        New = red(s)
    elif color == "green":
        New = green(s)
    elif color == "blue":
        New = blue(s)
    else:
        New = s
    return New
# ---------------------------------------------------
def color_tag(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    if "<red>" in s:
        s = s.replace("<red>","")
        s = s.replace("</>","")
        new = red(s)
    elif "<green>" in s:
        s = s.replace("<green>","")
        s = s.replace("</>","")
        new = green(s)
    elif "<blue>" in s:
        s = s.replace("<blue>","")
        s = s.replace("</>","")
        new = blue(s)
    return new
# ---------------------------------------------------
def highlight_words(s, words):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    for i in range(len(words)):
        new = highlight(words[i])
        n = s.find(words[i])
        s = s.replace(words[i],new)
    return s
# ---------------------------------------------------
def display_tag_file(filename):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    n = open('filename', 'r', encoding='utf-8')
    h = ["<red>","<green>","<blue>"]
    N = highlight_words(n, h)
    new = colortag(N)
    f = n.find("<red>","<green>","<blue>")
    for i in f:
        New = n.replace(n(i),new)
    return New

6431137021: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_10.0
[Non'\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0
[Non'\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display0.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 282, 'const': 253, 'code+const': 535}
def red(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return RED + s + RESET
# ---------------------------------------------------
def green(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return GREEN + s + RESET
# ---------------------------------------------------
def blue(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return BLUE + s + RESET
# ---------------------------------------------------
def highlight(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return HIGHLIGHT + s + RESET
# ---------------------------------------------------
def color_text(s, color):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    if color.lower() == 'red':
        w = red(s)
    elif color.lower() == 'green':
        w = green(s)
    elif color.lower() == 'blue':
        w = blue(s)
    else:
        w = s
    return w
# ---------------------------------------------------
def color_tag(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    a = s.find('<')
    b = s.find('>')
    b2 = s.find('</>')
    c = s[b+1:b2]
    color = s[a+1:b]
    return color_text(c,color)
# ---------------------------------------------------
def highlight_words(s, words):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    pass
# ---------------------------------------------------
def display_tag_file(filename):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    pass

6431141521: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_10.0
[Non'\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0
[Non'\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display0.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 184, 'const': 72, 'code+const': 256}
def red(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return RED+s+RESET
def green(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return GREEN+s+RESET
def blue(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
     return BLUE+s+RESET
def highlight(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    pass
# ---------------------------------------------------
def color_text(s, color):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    color.upper()
    if color in nn:
      i = nn.index(color)
      color = n[i]
    else:
      return str(s)
    return str(color + str(s) + RESET)
    pass
# ---------------------------------------------------
def color_tag(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    pass
# ---------------------------------------------------
def highlight_words(s, words):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    pass
# ---------------------------------------------------
def display_tag_file(filename):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    pass

6431149621: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display0.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc<red>rrr</>pf<green>ggg</>o<red>rr</>z<blue>bbb</>abc
[]
bytecount: {'code': 622, 'const': 830, 'code+const': 1452}
def red(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return '\033[;31m' + s + '\033[0m'
# ---------------------------------------------------
def green(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return '\033[;32m' + s + '\033[0m' 
# ---------------------------------------------------
def blue(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return '\033[;34m' + s + '\033[0m'
# ---------------------------------------------------
def highlight(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return '\033[;103m' + s + '\033[0m'
# ---------------------------------------------------
def color_text(s, color):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    if color.lower() == "red":
      return red(s)
    elif color.lower() == "green":
      return green(s)
    elif color.lower() == "blue":
      return blue(s)
    else :
      return s
# ---------------------------------------------------
def color_tag(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    color = s[:7]
    if "<red>" in color:
      return red(s[5:-3])
    if "<green>" in color:
      return green(s[7:-3])
    if "<blue>" in color:
      return blue(s[6:-3])
# ---------------------------------------------------
def highlight_words(s, words):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    for i in words:
      nextOcc = len(i)
      pos = 0
      while s.find(i, pos) != -1:  
        s = s[:s.find(i, pos)] + highlight(s[s.find(i, pos):(s.find(i, pos)+nextOcc)]) + s[(s.find(i, pos)+nextOcc):]
        pos = s.find(i, pos) + nextOcc
    return s
# ---------------------------------------------------
def display_tag_file(filename):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    file = open(filename, 'r', encoding='utf-8')
    for line in file:
      pos = 0
      result = ""
      while line.find("<", pos) != -1 :
        openTag = line.find("<", pos)
        closeTag = line.find("</>", openTag + 1)
        s = line[openTag:closeTag + 3]
        result = result + line[pos:openTag] + color_tag(s)
        pos = closeTag + 3
      if line.find("\n") != -1:
        result += line[pos:-2]
      else :
        result += line
      print(result)
    file.close()

6431416121: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_10.0NameError("name 't' is not defined")
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0NameError("name 't' is not defined")
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display0.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 856, 'const': 756, 'code+const': 1612}
def red(s):
    colour = RED + s + RESET
    return colour
# ---------------------------------------------------
def green(s):
    colour = GREEN + s + RESET
    return colour
# ---------------------------------------------------
def blue(s):
    colour = BLUE + s + RESET
    return colour
# ---------------------------------------------------
def highlight(s):
    colour = HIGHLIGHT + s + RESET
    return colour
# ---------------------------------------------------
def color_text(s, color):
    colour = color.lower()
    if colour == 'red':
        p = RED + s + RESET
    elif colour == 'blue':
        p = BLUE + s + RESET
    elif colour == 'green':
        p = GREEN + s + RESET
    else:
        p = s
    return p
# ---------------------------------------------------
def color_tag(s):
    s = s.replace('<', '>')
    x = s.split('>')
    text = x[2]
    colour = x[1]
    if colour == 'red':
        p = RED + text + RESET
    elif colour == 'blue':
        p = BLUE + text + RESET
    elif colour == 'green':
        p = GREEN + text + RESET
    elif colour == '/' :
        p = x[0]
    return p
# ---------------------------------------------------
def highlight_words(s, words):
    sentence = ''
    if len(words) != 0 :
        x = t.split(words[0])
        for i in range(len(x)-1) :
            sentence += x[i] + HIGHLIGHT + words[0] + RESET
        sentence += x[len(x)-1]
        word = words[1:]
        for k in range(len(word)) :
            x = sentence.split(word[k])
            sentence = x[0] + HIGHLIGHT + word[k] + RESET
            for i in range(len(x)-2) :
                sentence += x[i+1] + HIGHLIGHT + word[k] + RESET
            sentence += x[len(x)-1]
    else :
        sentence = s
    return sentence
# ---------------------------------------------------
def display_tag_file(filename) :
    file = open(filename, 'r', encoding='utf-8')
    s = ''
    for l in file :
        z = l.split('<')
        emtpy = []
        k = ''
        for i in range(len(z)) :
            x = z[i].find('/')
            if x >= 0 :
                emtpy.append(i)
        for i in emtpy :
            color,text = z[i-1].split('>')
            if color == 'red' :
                text = RED + text + RESET
            elif color == 'blue':
                text = BLUE + text + RESET
            elif color == 'green':
                text = GREEN + text + RESET
            z[i-1] = text
        for i in range(len(z)):
            k += z[i]
        ans = k.split('/>')
        for i in ans:
            s += i
    return s
#display_tag_file('มหาจุฬาลงกรณ์-tag.txt')

6431418421: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display0.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 864, 'const': 1424, 'code+const': 2288}
def red(s):
    o='\033[;31m'+s+'\033[0m'
    return o
# ---------------------------------------------------
def green(s):
    o='\033[;32m'+s+'\033[0m'
    return o
# ---------------------------------------------------
def blue(s):
    o='\033[;34m'+s+'\033[0m'
    return o
# ---------------------------------------------------
def highlight(s):
    o='\033[;103m'+s+'\033[0m'
    return o
# ---------------------------------------------------
def color_text(s, color):
    x=color.lower()
    if x == 'red':
        o='\033[;31m'+s+'\033[0m'
    elif x == 'blue':
        o='\033[;34m'+s+'\033[0m'
    elif x == 'green':
        o='\033[;32m'+s+'\033[0m'
    else:
        o=s
    return o
# ---------------------------------------------------
def color_tag(s):
    s=s.replace('<', '>')
    x=s.split('>')
    text =x[2]
    color =x[1]
    if color == 'red':
        o='\033[;31m'+text+'\033[0m'
    elif color == 'blue':
        o='\033[;34m'+text+'\033[0m'
    elif color == 'green':
        o='\033[;32m'+text+'\033[0m'
    elif color =='/':
        o = x[0]
    return o
# ---------------------------------------------------
def highlight_words(s, words):
    ans=''
    if len(words) != 0:
        x=s.split(words[0])
        for i in range(len(x)-1):
            ans+=x[i]+'\033[;103m'+words[0]+'\033[0m'
        ans+=x[len(x)-1]
        ww=words[1:]
        for n in range(len(ww)):
            x=ans.split(ww[n])
            ans=x[0]+'\033[;103m'+ww[n]+'\033[0m'
            for i in range(len(x)-2):
                ans+=x[i+1]+'\033[;103m'+ww[n]+'\033[0m'
            ans+=x[len(x)-1]
    else:
        ans = s
    return ans
# ---------------------------------------------------
def display_tag_file(filename):
    fily= open(filename, 'r' ,encoding='utf-8')
    for line in fily:
      z=line.split('<')
      idk=[]
      nea=''
      ans=''
      for i in range(len(z)):
          x=z[i].find('/')
          if x >=0:
              idk.append(i)
      for i in idk:
          color,text =z[i-1].split('>')
          if color == 'red':
              text='\033[;31m'+text+'\033[0m'
          elif color == 'blue':
              text='\033[;34m'+text+'\033[0m'
          elif color == 'green':
              text='\033[;32m'+text+'\033[0m'
          z[i-1] =text
      for i in range(len(z)):
          nea+=z[i]
      anss=nea.split('/>')
      for i in anss:
          ans+= i
    fily.close()
    return ans

6431501821: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_10.0
['\x1b[;103mabc\x1b[;103mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mdefgabcabbcbffgcda\x1bc[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[;103mAbbcbf\x1b[;103mfgG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mAbcAbbcbffGcdabcaaa\x1bc[0m']
test_display0.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 424, 'const': 307, 'code+const': 731}
def red(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return RED + s + RESET
# ---------------------------------------------------
def green(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return GREEN + s + RESET
# ---------------------------------------------------
def blue(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return BLUE + s + RESET
# ---------------------------------------------------
def highlight(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return HIGHLIGHT + s + RESET
# ---------------------------------------------------
def color_text(s, color):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    color = color.upper()
    c = ['RED','BLUE', 'GREEN']
    if color in c:
        if color == 'RED':
            return red(s)
        elif color == 'BLUE':
            return blue(s)
        else:
            return green(s) 
    else:
        return s
# ---------------------------------------------------
def color_tag(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    if s[1] == 'r':
        return red(s[5:-3])
    elif s[1] == 'g':
        return green(s[7:-3])
    elif s[1] == 'b':
        return blue(s[6:-3])
# ---------------------------------------------------
def highlight_words(s, words):
    for i in range(len(s)):
        for j in range(len(words)):
            if s[i:i+len(words[j])] in words[j]:
                s = s[:i] + highlight(words[j]) + s[i+len(words[j]):]
    return s
# ---------------------------------------------------
def display_tag_file(filename):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    pass

6431507621: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display0.0
abcrrrpkk

defgggocr

xyzbbbabc

abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 450, 'const': 635, 'code+const': 1085}
def red(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return RED + s + RESET
# ---------------------------------------------------
def green(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return GREEN + s + RESET
# ---------------------------------------------------
def blue(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return BLUE + s + RESET
# ---------------------------------------------------
def highlight(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return HIGHLIGHT + s + RESET
# ---------------------------------------------------
def color_text(s, color):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    c = color.upper()
    if c == 'GREEN':
      a = GREEN
    elif c == 'RED':
      a = RED
    elif c == 'BLUE':
      a = BLUE
    return a + s + RESET
# ---------------------------------------------------
def color_tag(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    x = s.split('<')
    color,text = x[1].split('>')
    if color.lower() == "red":
        c = RED
    if color.lower() == "blue":
        c = BLUE
    if color.lower() == "green":
        c = GREEN
    return c + text + RESET
# ---------------------------------------------------
def highlight_words(s, words):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    b = s
    for a in words:
        b = b.replace(a,highlight(a))
    return b
def display_tag_file(filename):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    f = open(filename, 'r', encoding='utf-8')
    a = []
    for line in f:
        a.append(line)
    f.close()
    p = []
    for i in a:
        x = i
        x = x.replace("<red>", "\033[;31m")
        x = x.replace("<blue>", "\033[;34m")
        x = x.replace("<green>", "\033[;32m")
        p.append(x)
    for q in p:
        y = q
        y = y.replace("</>", "\033[0m")
        print(y)
    return

6431510421: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_10.0
['\x1b[;103mabc\x1b[0mdefgabcabbcbffgcdabcaaabcdefgabcabbcbffgcdabcaaabcdefgabcabbcbffgcdabcaaabcdefgabcabbcbffgcdabcaaabcdefgabcabbcbffgcdabcaaabcdefgabcabbcbffgcdabcaaabcdefgabcabbcbffgcdabcaaabcdefgabcabbcbffgcdabcaaabcdefgabcabbcbffgcdabcaaabcdefgabcabbcbffgcdabcaaabcdefgabcabbcbffgcdabcaaabcdefgabcabbcbffgcdabcaaabcdefgabcabbcbffgcdabcaaabcdefgabcabbcbffgcdabcaaabcdefgabcabbcbffgcdabcaaabcdefgabcabbcbffgcdabcaaabcdefgabcabbcbffgcdabcaaabcdefgabcabbcbffgcdabcaaabcdefgabcabbcbffgcdabcaaabcdef ... (more)
test_highlight_20.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0mAbcAbbcbffGcdabcaaabcAbcAbbcbffGcdabcaaabcAbcAbbcbffGcdabcaaabcAbcAbbcbffGcdabcaaabcAbcAbbcbffGcdabcaaabcAbcAbbcbffGcdabcaaabcAbcAbbcbffGcdabcaaabcAbcAbbcbffGcdabcaaa\x1bc[;103mAbcAbbcbffGcdabcaaabcA\x1bc[0mAbbcbffGcda\x1bcaaabcAbcAbbcbf[;103mfGcda\x1bcaaabcAbcAbbcbffGcdabcaaabcAbcAbbcbffGcdabcaaabcAbcAbbcbffGcdabcaaabcAbcAbbcbffGcdabcaaabcAbcAbbcbffGcdabcaaabcAbcAbbcbffGcdabcaaabcAbcAbbcbffGcdabcaaabcAbcAbbcbffGcdabcaaabcAbcAbbcbffGcdabcaaabcAbcAbbcbff ... (more)
test_display1.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 1024, 'const': 592, 'code+const': 1616}
def red(s):
    s = RED + s + RESET
    return s
# ---------------------------------------------------
def green(s):
    s = GREEN + s + RESET
    return s
# ---------------------------------------------------
def blue(s):
    s = BLUE + s + RESET
    return s
# ---------------------------------------------------
def highlight(s):
    s = HIGHLIGHT + s + RESET
    return s
# ---------------------------------------------------
def color_text(s, color):
    color = color.lower()
    if color == 'red':
        s = red(s)
    elif color == 'green':
        s = green(s)
    elif color == 'blue':
        s = blue(s)
    else:
        return s
    return s
# ---------------------------------------------------
def color_tag(s):
    a = s.find('>')
    a1 = s.find('<')
    b = s.find('<',a)
    c = s[a1+1:a]
    d = s[a+1:b]
    if c == 'red':
        d = red(d)
    elif c == 'green':
        d = green(d)
    elif c == 'blue':
        d = blue(d)
    return d
# ---------------------------------------------------
def highlight_words(s, words):
    d = []
    d1 = []
    f = []
    x = 0
    y = 0
    ans = ''
    for ch in words:
        d1 = []
        d1 += [len(ch)]
        for i in range(len(s)-len(ch)+1):
            if s[i:i+len(ch)] == ch:
                d1.append(i)
            elif s[i:i+len(ch)] != ch:
                d1 += []
                d += [d1]
    for e in d:
        for i in range(1,len(e)):
            x = e[i]+e[0]
            f.append([e[i]]+[x])
            f.sort()
    for e in f:
        for i in range(len(s)):
            if i<y:
                ans += ''
            elif i == e[0]:
                ans += highlight(s[e[0]:e[1]])
                y = 0
                y += e[1]
                break
            elif i != e[0]:
                ans += s[i]
    if f == []:
        return s
    else:
        ans += s[f[-1][1]::1]
        return ans
# ---------------------------------------------------
def display_tag_file(filename):
     infile = open(filename, 'r', encoding='utf-8')
     ans = ''
     for line in infile:
         a = line.find('<',0)
         b = line.find('/',0)
         if a == -1 and b == -1:
             ans += line[0:]
         else:
             a = 0
             b = 0
             c = 0
             s = ''
             while b != -1:
                 a = line.find('<',a)
                 b = line.find('/',b)
                 s += line[c:a]+color_tag(line[a:b+2])
                 c = b+2
                 b = line.find('/',b+1)
                 a = line.find('<',c)
                 if b == -1:
                     ans += s+line[c:]
     infile.close
     print(ans)

6431513321: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display1.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 484, 'const': 412, 'code+const': 896}
def red(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return RED+s+RESET
# ---------------------------------------------------
def green(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return GREEN+s+RESET
# ---------------------------------------------------
def blue(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return BLUE+s+RESET
# ---------------------------------------------------
def highlight(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return  HIGHLIGHT+s+RESET
# ---------------------------------------------------
def color_text(s, color):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    x=color.lower()
    if x=='red':
      return red(s)
    elif x=='green':
      return green(s)
    elif x=='blue':
      return blue(s)
    return s
# ---------------------------------------------------
def color_tag(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    l=s.split('>')
    color=l[0][1:]
    text=l[1][:len(l[1])-2]
    return color_text(text, color)
# ---------------------------------------------------
def highlight_words(s, words):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน 
    text=s
    for temp1 in words:
        l=text.split(temp1)
        text=highlight(temp1).join(l)
    return text
# ---------------------------------------------------
def display_tag_file(filename):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    infile = open(filename, 'r', encoding='utf-8')
    newline=''
    for line in infile:
      newline+=line
    ans=''
    while True:
      index=newline.find('<')
      if index!=-1:
        ans+=newline[:index]
        newline=newline[index:]
      else:
        ans+=newline
        break
      k=newline.find('/')
      if k!=-1:
        changed=color_tag(newline[:k+2])
        ans+=changed
        newline=newline[k+2:]
    infile.close()
    print(ans)

6431517921: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display0.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 534, 'const': 523, 'code+const': 1057}
def red(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    result = RED + s + RESET
    return result
# ---------------------------------------------------
def green(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    result = GREEN + s + RESET
    return result
# ---------------------------------------------------
def blue(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    result = BLUE + s + RESET
    return result
# ---------------------------------------------------
def highlight(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    result = HIGHLIGHT + s + RESET
    return result
# ---------------------------------------------------
def color_text(s, color):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    if color.lower()=="red":
      return red(s)
    if color.lower()=="green":
      return green(s)
    if color.lower()=="blue":
      return blue(s)
    return s
# ---------------------------------------------------
def color_tag(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    s = s.replace(">","<")
    s = s.split("<")
    result = ""
    i = 0
    while i < len(s):
      if s[i] == "red" or s[i] == "green" or s[i] == "blue":
        j = 1
        while s[i+j] != "/":
           result = result + color_text(s[i+j], s[j])
           j+=1
        i+=(j+1)
      else:
        result = result + s[i]
        i+=1
    return result  
# ---------------------------------------------------
def highlight_words(s, words):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    for word in words:
      tmp = ""
      list = s.split(word)
      for i in range(len(list)):
        if i == 0:
          tmp = tmp + list[i]
        else:
          tmp = tmp + highlight(word) + list[i]
      s = tmp
    return s      
# ---------------------------------------------------
def display_tag_file(filename):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    file = open(filename, "r", encoding="utf-8")
    s=""
    for line in file:
      s = s+line
    print(color_tag(s))
#print('RED', red('Hello'))
#print('green text:', green('green text'), 'and normal text')
#print('blue text:', blue('blue text'), 'and normal text')
#print('highlight text:', highlight('highlight text'), 'and normal text')
#print(color_text('This is red text', 'red'))	
#print(color_text('This is green text', 'GreeN'))	
#print(color_text('This is blue text', 'BLUE'))	
#print(color_text('This is yellow text', 'yellow'))
#print(color_tag('<red>red text</>'))	
#print(color_tag('<green>green text</>'))	
#print(color_tag('<blue>blue text</>'))
#t = 'a[3]มิใช่ลิสต์ คืนค่ามิใช่print =มิใช่เปรียบเทียบ รักมิใช่ดวงดาวที่พราวแสง'
#print(highlight_words(t,['มิใช่']))	 
#print(highlight_words(t,['ลิสต์']))	
#print(highlight_words(t, []))	
#w = ['print', 'ดาว', 'มิใช่']
#z = highlight_words(t, w)
#print(z)
#display_tag_file('มหาจุฬาลงกรณ์-tag-2.txt')

6431523621: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display1.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 622, 'const': 583, 'code+const': 1205}
def red(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return RED+s+RESET
# ---------------------------------------------------
def green(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return GREEN+s+RESET
# ---------------------------------------------------
def blue(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return BLUE+s+RESET
# ---------------------------------------------------
def highlight(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return HIGHLIGHT+s+RESET
# ---------------------------------------------------
def color_text(s, color):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    if color.upper()=='RED' :
        return RED+s+RESET
    elif color.upper()=='GREEN' :
        return GREEN+s+RESET
    elif color.upper()=='BLUE' :
        return BLUE+s+RESET
    else :
        return s
# ---------------------------------------------------
def color_tag(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    start = s.find('>')
    stop = s.find('<',1)
    text = s[start+1:stop]
    if s[1].upper()=='R' :
        return RED+text+RESET
    elif s[1].upper()=='G' :
        return GREEN+text+RESET
    elif s[1].upper()=='B' :
        return BLUE+text+RESET
# ---------------------------------------------------
def highlight_words(s, words):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    if words==[] :
        return s
    else :
        show = s
        for e in words :
            lt = show.split(e)
            show = ''
            for i in range(len(lt)-1) :
                show+=(lt[i]+(HIGHLIGHT+e+RESET))
            show+=lt[-1]
        return show
# ---------------------------------------------------
def display_tag_file(filename):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    infile = open(filename, 'r', encoding='utf-8')
    ans = []
    for line in infile :
        line = line.rstrip()
        if len(line)==0 : break
        else :
            t = ''
            i = 0
            while i<len(line) :
                if line[i]!='<' :
                    t+=line[i]
                    i+=1
                else :
                    k = line.find('/',i)
                    t+=color_tag(line[i:k+2])
                    i = k+2
            ans.append(t)
    infile.close()
    print('\n'.join(ans))

6431526521: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_10.0
[Non'\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0
[Non'\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display0.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 132, 'const': 313, 'code+const': 445}
def red(s):
    return ('\033[;31m'+s+'\033[0m')
# ---------------------------------------------------
def green(s):
    return ('\033[;32m'+s+'\033[0m')
# ---------------------------------------------------
def blue(s):
    return ('\033[;34m'+s+'\033[0m')
# ---------------------------------------------------
def highlight(s):
    return ('\033[;103m'+s+'\033[0m')
# ---------------------------------------------------
def color_text(s, color):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    pass
# ---------------------------------------------------
def color_tag(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    pass
# ---------------------------------------------------
def highlight_words(s, words):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    pass
# ---------------------------------------------------
def display_tag_file(filename):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    pass

6431527121: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display0.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 414, 'const': 762, 'code+const': 1176}
def red(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return ('\033[;31m' + s + '\033[0m')
# ---------------------------------------------------
def green(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return ('\033[;32m' + s + '\033[0m')
# ---------------------------------------------------
def blue(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return ('\033[;34m' + s + '\033[0m')
# ---------------------------------------------------
def highlight(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return ('\033[;103m' + s + '\033[0m')
# ---------------------------------------------------
def color_text(s, color):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    if  color.lower() in ['red' , 'Red']:
      return ('\033[;31m'+s+'\033[0m')
    elif color.lower() in ['green' , 'Green']:
      return ('\033[;32m'+s+'\033[0m')
    elif color.lower() in ['blue' , 'Blue' ]:
      return ('\033[;34m'+s+'\033[0m')
# ---------------------------------------------------
def color_tag(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    if s.startswith('<red>') and s.endswith('</>'):
        s=s.removeprefix('<red>')
        s=s.removesuffix('</>')
        return ('\033[;31m'+s+'\033[0m')
    elif s.startswith('<blue>') and s.endswith('</>'):
        s=s.removeprefix('<blue>')
        s=s.removesuffix('</>')
        return ('\033[;34m'+s+'\033[0m')
    elif s.startswith('<green>') and s.endswith('</>'):
        s=s.removeprefix('<green>')
        s=s.removesuffix('</>')
        return ('\033[;32m'+s+'\033[0m')
# ---------------------------------------------------
def highlight_words(s, words):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    for word in words:
        if (word.lower() in s.lower()):
            s=s.split(word)
            s=highlight(word).join(s)
    return s
# ---------------------------------------------------
def display_tag_file(filename):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    pass

6431540221: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_10.0NameError("name 'highlight_words' is not defined")
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0NameError("name 'highlight_words' is not defined")
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display0.0NameError("name 'display_tag_file' is not defined")
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 312, 'const': 292, 'code+const': 604}
def red(s):
    result = RED+s+RESET
    return result
# ---------------------------------------------------
def green(s):
    result = GREEN+s+RESET
    return result
# ---------------------------------------------------
def blue(s):
    result = BLUE+s+RESET
    return result
# ---------------------------------------------------
def highlight(s):
    result = HIGHLIGHT+s+RESET
    return result
# ---------------------------------------------------
def color_text(s, color):
    c = color.lower()
    if c == 'red' :
        r = red(s)
        return r
    elif c == 'green' :
        r = green(s)
        return r
    elif c == 'blue' :
        r = blue(s)
        return r
    else :
        return s
# ---------------------------------------------------
def color_tag(s):
    if '<red>' in s :
        text = s[5:-3]
        r = red(text)
        return r
    elif '<green>' in s :
        text = s[7:-3]
        r = green(text)
        return r
    elif '<blue>' in s :
        text = s[6:-3]
        r = blue(text)
        return r
    else :
        return s

6431804021: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display0.0
abcrrrpkk

defgggocr

xyzbbbabc

abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 712, 'const': 423, 'code+const': 1135}
def red(s):
    t=RED+s+RESET
    return t
# ---------------------------------------------------
def green(s):
    t=GREEN+s+RESET
    return t
# ---------------------------------------------------
def blue(s):
    t=BLUE+s+RESET
    return t
# ---------------------------------------------------
def highlight(s):
    t=HIGHLIGHT+s+RESET
    return t
# ---------------------------------------------------
def color_text(s, color):
    c=color.lower()
    if c=='red':
        s=red(s)
    elif c=='green':
        s=green(s)
    elif c=='blue':
        s=blue(s)
    return s
# ---------------------------------------------------
def color_tag(s):
    i=s.find(">")
    color=s[1:i]
    ss=s[i+1::]
    j=ss.find("<")
    ss=ss[:j]
    t=color_text(ss, color)
    return t
# ---------------------------------------------------
def highlight_words(s, words):
    w=[]
    tt=s
    if len(words)>0:
        for e in words:
            start=s.find(e)
            end=len(e)
            t=highlight(s[start:start+end])
            w.append(t)
        for i in range(len(words)):
            tt=tt.replace(words[i],w[i])
        return tt
    else:
        return s
# ---------------------------------------------------
def display_tag_file(filename):
    fo=open(filename, 'r', encoding='utf-8')
    for line in fo:
        li=line
        i=0
        w1=[]
        w2=[]
        while i>=0:
            i=li.find("<")
            j=li.find(">")
            l=li[j+1::]
            k=l.find(">")
            s=li[i:j+k+2]
            ii=s.find(">")
            color=s[1:ii]
            ss=s[ii+1::]
            jj=ss.find("<")
            ss=ss[:jj]
            w1.append(s)
            t=color_tag(s)
            w2.append(t)
            # print(li,i,j,k)
            # print(l)
            # print(s,t)
            li=li[j+k+2::]
            # print(li)
            if k==-1: break
        for i in range(len(w1)):
            line=line.replace(w1[i],w2[i])
        print(line)
    fo.close()

6432032021: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_10.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display0.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 698, 'const': 613, 'code+const': 1311}
def red(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return RED+s+RESET
# ---------------------------------------------------
def green(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return GREEN+s+RESET
# ---------------------------------------------------
def blue(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return BLUE+s+RESET
# ---------------------------------------------------
def highlight(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return HIGHLIGHT+s+RESET
# ---------------------------------------------------
def color_text(s, color):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    if color.lower() in ['red','green','blue']:
        if color.lower() == 'red':
            return red(s)
        elif color.lower() == 'green':
            return green(s)
        else:
            return blue(s)
    else:
        return s
# ---------------------------------------------------
def color_tag(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    fc = s.index('<')
    bc = s.index('>')
    rs = s.find('</>')
    if fc != -1:
        if s[fc+1:bc] == 'red':
            return red(s[bc+1:rs])
        elif s[fc+1:bc] == 'green':
            return green(s[bc+1:rs])
        elif s[fc+1:bc] == 'blue':
            return blue(s[bc+1:rs])
# ---------------------------------------------------
def highlight_words(s, words):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    s = s.split()
    result = ''
    for i in words:
        for j in range(len(s)):
            f = s[j].find(i)
            if f != -1:
                s[j] = s[j][:f]+highlight(s[j][f:f+len(i)])+s[j][f+len(i):]
    for i in s:
        result += i+' '
    return result[:-1]
# ---------------------------------------------------
def display_tag_file(filename):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    fn = open(filename, 'r', encoding='utf-8')
    read = ''
    result = ''
    for i in fn:
       read += i
    while read.find('<') != -1 :
         fc = read.find('<')
         rs = read.find('</>')
         result += read[:fc]
         result += color_tag(read[fc:rs+3])
         read = read[rs+3:]
         if read.find('<') == -1:
             result += read
    return result

6432036521: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display0.0
abcrrrpkk

defgggocr

xyzbbbabc

abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 558, 'const': 738, 'code+const': 1296}
def red(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return '\033[;31m'+s+'\033[0m'
# ---------------------------------------------------
def green(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return '\033[;32m'+s+'\033[0m'
# ---------------------------------------------------
def blue(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return '\033[;34m'+s+'\033[0m'
# ---------------------------------------------------
def highlight(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return '\033[;103m'+s+'\033[0m'
# ---------------------------------------------------
def color_text(s, color):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    if color.lower() == 'red':
      return red(s)
    elif color.lower() == 'green':
      return green(s)
    elif color.lower() == 'blue':
      return blue(s)
    return s
# ---------------------------------------------------
def color_tag(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    color = ''
    text = ''
    i = 1
    while s[i]!='>':
      color+=s[i]
      i+=1
    i+=1
    while s[i]!='<' or s[i:i+3] != '</>':
      text += s[i]
      i+=1
    return color_text(text, color)
# ---------------------------------------------------
def highlight_words(s, words):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    text = ''
    for c in words:
      while s.find(c) != -1 :
        n = s.find(c)
        text+=s[:n]+highlight(s[n:n+len(c)])
        s=s[n+len(c):]
      s=text+s
      text=''
    return s
# ---------------------------------------------------
def display_tag_file(filename):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    file = open(filename, 'r', encoding='utf-8')
    for line in file.readlines():
      while line.find('</>') != -1:
        start=line.find('<')
        stop=line.find('</>')
        line =line[:start]+color_tag(line[start:stop+3])+line[stop+3:]
      print(line)
#display_tag_file('มหาจุฬาลงกรณ์-tag.txt')

6530001221: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_21.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display0.0FileNotFoundError("No such file or directory: 'มหาจุฬาลงกรณ์-tag.txt'")
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 1078, 'const': 1079, 'code+const': 2157}
def red(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    r = '\033[;31m'
    for e in s :
        r += e
    r += '\033[0m'
    return r
# ---------------------------------------------------
def green(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    g = '\033[;32m'
    for e in s :
        g += e
    g += '\033[0m'
    return g
# ---------------------------------------------------
def blue(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    b = '\033[;34m'
    for e in s :
        b += e
    b += '\033[0m'
    return b
# ---------------------------------------------------
def highlight(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    h = '\033[;103m'
    for e in s :
        h += e
    h += '\033[0m'
    return h
# ---------------------------------------------------
def color_text(s, color):
    color = color.lower()
    if color == 'red' :
        return red(s)
    elif color == 'green' :
        return green(s)
    elif color == 'blue' :
        return blue(s)
    else :
        return s
# ---------------------------------------------------
def color_tag(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    for i in range(len(s)) :
        if s[:5] == '<red>' :
            return red(s[5:-3])
        if s[:7] == '<green>' :
            return green(s[7:-3])
        if s[:6] == '<blue>' :
            return blue(s[6:-3])
# ---------------------------------------------------
def highlight_words(s, words):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    b = s
    j = 0
    for i in range(len(words)) :
        j = 0
        a = ''
        while j < len(b) :
            if j <= len(b)-len(words[i]) :
                if b[j:j+len(words[i])].lower() == words[i].lower() :
                    h = '\033[;103m'
                    h += b[j:j+len(words[i])]
                    h += '\033[0m'
                    a += h
                    j += len(words[i])
                else :
                    a += b[j]
                    j += 1
            else:
                a += b[j]
                j += 1
        b = a
    return b
# ---------------------------------------------------
def display_tag_file(filename):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    x = open('มหาจุฬาลงกรณ์-tag.txt', 'r', encoding='utf-8')
    j = 0
    ans=''
    d = '<red>'
    g = '<green>'
    e = '<blue>'
    for Row in x :
        j = 0
        a = ''
        b = ''
        c = ''
        while j < len(Row) :
            a=''
            b=''
            if Row[j:j+5] == '<red>' :
                r = Row.find('<',j+5)
                a += Row[j+5:r]
                b = red(a)
                c += b
                j += r-j+3
            elif Row[j:j+7] == '<green>' :
                r = Row.find('<',j+7)
                a += Row[j+7:r]
                b = green(a)
                c += b
                j += r-j+3
            elif Row[j:j+6] == '<blue>' :
                r = Row.find('<',j+6)
                a += Row[j+6:r]
                b = blue(a)
                c += b
                j += r-j+3
            elif Row[j:j+3] == '</>' :
                pass
            else :
                c += Row[j]
                j += 1
        ans+=c
    x.close()
    return print(ans)

6530002921: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display0.0
abcrrrpkk

defgggocr

xyzbbbabc

abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 1056, 'const': 521, 'code+const': 1577}
def red(s):
  return RED+s+RESET
# ---------------------------------------------------
def green(s):
  return GREEN+s+RESET
# ---------------------------------------------------
def blue(s):
  return BLUE+s+RESET
# ---------------------------------------------------
def highlight(s):
  return HIGHLIGHT+s+RESET
# ---------------------------------------------------
def color_text(s, color):
  if color.lower() == 'red':
    return red(s)
  elif color.lower() == 'green':
    return green(s)
  elif color.lower() == 'blue':
    return blue(s)
  elif color.lower() == 'highlight':
    return highlight(s)
# ---------------------------------------------------
def color_tag(s):
  stack = ""
  start_color_tag = len(s)+1
  end_color_tag = len(s)+1
  reset = 0
  count = (s.count('<'))/2
  check = 0
  if count != 0:
    for i in range(len(s)) :
      char = s[i]
      if char == '<' and start_color_tag == len(s)+1:
        start_color_tag = i
        check = 1
      elif char == '>' and end_color_tag == len(s)+1:
        end_color_tag = i
      elif char == '<' and check == 1:
        reset = i
        check = 0
    #color = s[start_color_tag+1, end_color_tag]
    #color_part = s[end_color_tag+1: reset]
    if s[0] != '<':
      stack += s[0: start_color_tag]
    stack += str(color_text(s[end_color_tag+1: reset], s[start_color_tag+1: end_color_tag]))
    if reset != len(s)-1:
      if count == 1:
        stack += s[reset+3:]
      elif count > 1:
        stack += color_tag(s[reset+3:])
    #stack_extend = s[reset+3:]
    return stack
  if count == 0:
    return s
# ---------------------------------------------------
def highlight_words(s, words):
  stack = ""
  if len(words) == 0:
    return s
  elif len(words) != 0:
    current_index = 0
    exact_index = 0
    index = -2
    word = words[0]
    count = s.count(word)
    for i in range(count):
      if index == -2:
        index = s.find(word)
        if s[:index] != None:
          stack += s[:index]
          stack += color_text(s[index:index+len(word)], 'highlight')
        else:
          stack += color_text(s[index:index+len(word)], 'highlight')
        exact_index = index
      elif index != -1:
        current_index = index + len(word)
        index = s[index+len(word):].find(word)
        exact_index = current_index + index
        if s[current_index:index] != None:
          stack += s[current_index:exact_index]
          stack += color_text(s[exact_index:exact_index+len(word)], 'highlight')
        else:
          stack += color_text(s[exact_index:exact_index+len(word)], 'highlight')
        index = exact_index
    if s[exact_index+len(word):] != None:
      stack += s[exact_index+len(word):]
    stack = highlight_words(stack, words[1:])
    return stack
# ---------------------------------------------------
def display_tag_file(filename):
  file = open(filename, 'r', encoding='utf-8')
  for line in file:
    print(color_tag(str(line)))
  file.close()

6530003521: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_10.0
['\x1b[;103ma\x1b[0m\x1b[;103mb\x1b[0m\x1b[;103mc\x1b[0mde\x1b[;103mf\x1b[0m\x1b[;103mg\x1b[0m\x1b[;103ma\x1b[0m\x1b[;103mb\x1b[0m\x1b[;103mc\x1b[0mabbcbf\x1b[;103mf\x1b[0m\x1b[;103mg\x1b[0mcd\x1b[;103ma\x1b[0m\x1b[;103mb\x1b[0m\x1b[;103mc\x1b[0maa\x1b[;103ma\x1b[0m\x1b[;103mb\x1b[0m\x1b[;103mc\x1b[0m']
test_highlight_20.0
['\x1b[;103ma\x1b[0m\x1b[;103mB\x1b[0m\x1b[;103mC\x1b[0mde\x1b[;103mf\x1b[0m\x1b[;103mg\x1b[0m\x1b[;103mA\x1b[0m\x1b[;103mb\x1b[0m\x1b[;103mc\x1b[0mAbbcbf\x1b[;103mf\x1b[0m\x1b[;103mG\x1b[0mcd\x1b[;103ma\x1b[0m\x1b[;103mb\x1b[0m\x1b[;103mc\x1b[0maa\x1b[;103ma\x1b[0m\x1b[;103mb\x1b[0m\x1b[;103mc\x1b[0m']
test_display0.0
abcrrrpkk

defgggocr

xyzbbbabc

abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 560, 'const': 591, 'code+const': 1151}
def red(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return RED+s+RESET
# ---------------------------------------------------
def green(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return GREEN+s+RESET
# ---------------------------------------------------
def blue(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return BLUE+s+RESET
# ---------------------------------------------------
def highlight(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return HIGHLIGHT+s+RESET
# ---------------------------------------------------
def color_text(s,color):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    c = color.lower()
    if c == 'red' :
        return red(s)
    elif c == 'blue' :
        return blue(s)
    elif c == 'green' :
        return green(s) 
    else :
        return s
# ---------------------------------------------------
def color_tag(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    s = s.replace('<red>','!<red>').replace('<blue>','!<blue>').replace('<green>','!<green>').replace('</>','</>!').split('!')
    t = ''
    for e in s :
        if '<red>' in e :
            t += e.replace(e,red(e)).replace('<red>','').replace('</>','')
        elif '<blue>' in e :
            t += e.replace(e,blue(e)).replace('<blue>','').replace('</>','')
        elif '<green>' in e :
            t += e.replace(e,green(e)).replace('<green>','').replace('</>','')
        else :
            t+=e
    return t
# ---------------------------------------------------
def highlight_words(s, words):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    a = ''
    t = s.lower()
    for e in words :
        t = t.replace(e.lower(),('1'*len(e)))
    for i in range(len(t)) :
        if t[i] == '1' :
          a += highlight(s[i]) 
        else :
          a+=s[i]
    return a
# ---------------------------------------------------
def display_tag_file(filename):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    f = open( filename, 'r' , encoding='utf-8')
    for line in f :
       print(color_tag(line))

6530005821: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_21.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display1.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 752, 'const': 609, 'code+const': 1361}
def red(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return RED +str(s)+ RESET
# ---------------------------------------------------
def green(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return GREEN +str(s)+ RESET
# ---------------------------------------------------
def blue(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return BLUE +str(s)+ RESET
# ---------------------------------------------------
def highlight(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return HIGHLIGHT+ str(s) + RESET
# ---------------------------------------------------
def color_text(s, color):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    if color.lower() == 'red':
        c = red(s)
    elif color.lower() == 'green':
        c = green(s)
    elif color.lower() == 'blue':
        c = blue(s)
    else:
        c = str(s)
    return c
# ---------------------------------------------------
def color_tag(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    for e in s:
        g1 = s.find('<')
        g2 = s.find('>')
        c = s[g1+1:g2]
    for e in s:
        g3 = s.rfind('</>')
        w = s[g2+1:g3]
    return color_text(w,c)
#---------------------------------------------------
def where(s,w):
    a=[]
    c = s.lower()
    for e in w:
        if e!='':
            k = c.count(e.lower())
            j = -1
            for i in range(k):
                j = c.find(e.lower(),j+1)
                a += [[j,e]]
                if j == -1:
                    j = -1
    return a
# ---------------------------------------------------
def highlight_words(s, words):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    c = where(s,words)
    c.sort()
    f = ''
    p = ''
    o = 0
    for [x1,x2]  in c:
        p = s[x1:x1+len(x2)]
        p = highlight(p)
        c = s[o:x1]
        o = x1+len(x2)
        f += c+p
    f += s[o:]
    return f    
# ---------------------------------------------------
def display_tag_file(filename):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
  f = open(filename, 'r', encoding='utf-8')
  x = f.readlines() 
  f.close()
  y = "".join(x)
  c = where(y,['<red>','<green>','<blue>'])
  c.sort()
  o = 0
  a =  ''
  for [x1,x2] in c:
    k = y.find('</>',x1)+3
    end = color_tag(y[x1:k])
    front = y[o:x1]
    o = k
    L = front + end
    a+=L
  a += y[k:]
  print(a)

6530006421: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_21.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display1.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 484, 'const': 399, 'code+const': 883}
def red(s) :
    return RED + s + RESET
# ---------------------------------------------------
def green(s) :
    return GREEN + s + RESET
# ---------------------------------------------------
def blue(s) :
    return BLUE + s + RESET
# ---------------------------------------------------
def highlight(s) :
    return HIGHLIGHT + s + RESET
# ---------------------------------------------------
def color_text(s, colour) :
    valid_colour = [RED, GREEN, BLUE]
    colour_list = ["RED", "GREEN", "BLUE"]
    colour = colour.upper()
    if colour in colour_list :
        return valid_colour[colour_list.index(colour)] + s + RESET
    else :
        return s
# ---------------------------------------------------
def color_tag(s) :
    return s.replace("<red>", RED).replace("<green>", GREEN).replace("<blue>", BLUE).replace("</>", RESET)
# ---------------------------------------------------
def highlight_words(s, words) :
    check_s = s.lower()
    check_words = [word.lower() for word in words]
    to_be_highlight = []
    for word in check_words :
        n = check_s.count(word)
        if n :
            previous_pos = 0
            for i in range(n) :
                current_pos = check_s.find(word, previous_pos)
                end_of_current = current_pos + len(word)
                need_word = s[current_pos:end_of_current]
                if need_word not in to_be_highlight :
                    to_be_highlight.append(need_word)
                previous_pos = end_of_current
    for word in to_be_highlight :
        s = s.replace(word, highlight(word))
    return s
# ---------------------------------------------------
def display_tag_file(filename) :
    with open(filename, 'r', encoding = 'utf-8') as op_file :
        temp = [color_tag(line) for line in op_file]
    print("".join(temp))
# =================================================== end of program;

6530007021: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_21.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display1.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 542, 'const': 694, 'code+const': 1236}
def red(s):
    return '\033[;31m'+s+'\033[0m'
# ---------------------------------------------------
def green(s):
    return '\033[;32m'+s+'\033[0m'
# ---------------------------------------------------
def blue(s):
    return '\033[;34m'+s+'\033[0m'
# ---------------------------------------------------
def highlight(s):
    return '\033[;103m'+s+'\033[0m'
# ---------------------------------------------------
def color_text(s, color):
    if color.lower() == 'red':
        return red(s)
    elif color.lower() == 'green':
        return green(s)
    elif color.lower() == 'blue':
        return blue(s)
    else:
        return s
# ---------------------------------------------------
def color_tag(s):
    a = s.find('<')
    b = s.find('>')
    color = s[a+1:b]
    x = s.find('<',a+1)
    text = s[b+1:x]
    return s[:a]+color_text(text,color)+s[x+3:]
# ---------------------------------------------------
def highlight_words(s, words):
    for i in words:
        a = s.lower().find(i.lower())
        while a != -1:
            s = s[:a] + highlight(s[a:a+len(i)]) + s[a+len(i):]
            a = s.lower().find(i.lower(),a+len(highlight(i)))
    return s
# ---------------------------------------------------
def display_tag_file(filename):
    f = open(filename,'r',encoding='utf-8')
    line = []
    for i in f:
      line.append(i)
    line = ''.join(line)
    while '<red>' in line or '<green>' in line or '<blue>' in line :
      line = color_tag(line)
    f.close()
    print(line)

6530008721: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display1.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 346, 'const': 360, 'code+const': 706}
def red(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return (RED+s+RESET)
# ---------------------------------------------------
def green(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return (GREEN+s+RESET)
# ---------------------------------------------------
def blue(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return (BLUE+s+RESET)
# ---------------------------------------------------
def highlight(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return (HIGHLIGHT+s+RESET)
# ---------------------------------------------------
def color_text(s, color):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    s = s.strip()
    op = color.lower()
    if op == 'blue':
        return blue(s)
    elif op == 'red':
        return red(s)
    elif op == 'green':
        return green(s)
    else:
        return s
# ---------------------------------------------------
def color_tag(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    s = s.strip()
    s = s.replace('<red>', RED).replace('<green>', GREEN).replace('<blue>', BLUE).replace('</>', RESET)
    return s
# ---------------------------------------------------
def highlight_words(s, words):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    s = s.strip()
    for e in words:
        s = s.split(e)
        s = (highlight(e).join(s))
    return s
# ---------------------------------------------------
def display_tag_file(filename):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    fn = open(filename, 'r', encoding='utf-8')
    for line in fn:
        print (color_tag(line))
    fn.close()

6530009321: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_21.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display0.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 590, 'const': 590, 'code+const': 1180}
def red(s):
    return RED+s+RESET
# ---------------------------------------------------
def green(s):
    return GREEN+s+RESET
# ---------------------------------------------------
def blue(s):
    return BLUE+s+RESET
# ---------------------------------------------------
def highlight(s):
    return HIGHLIGHT+s+RESET
# ---------------------------------------------------
def color_text(s, color):
    lower_color = color.lower()
    if lower_color == "red":
        return red(s)
    elif lower_color == "green":
        return green(s)
    elif lower_color == "blue":
        return blue(s)
    else:
        return s
# ---------------------------------------------------
def color_tag(s):
    newS = ""
    skip = 0
    for i in range(len(s)):
        if s[i] == '<':
            if s[i:i+5] == '<red>':
                skip = 4
                newS += RED
            elif s[i:i+6] == '<blue>':
                skip = 5
                newS += BLUE
            elif s[i:i+7] == '<green>':
                skip = 6
                newS += GREEN
            elif s[i:i+3] == '</>':
                skip = 2
                newS += RESET
        else:
            if skip > 0:
                skip -= 1
            else:
                newS += s[i]
    return newS
# ---------------------------------------------------
def highlight_words(s, words):
    tempS = s[:]
    for word in words:
        newS = ""
        pos = -1
        previousPos = 0
        while True:
            pos = tempS.lower().find(word.lower(), pos + 1)
            #if not found. add from previousPos to the end of the list
            if pos == -1:
                newS += tempS[previousPos:len(tempS)]
                tempS = newS
                break
            else:
                #add from previous position to this found position
                newS += tempS[previousPos:pos]
                previousPos = pos+len(word)
                #Highlight the word
                newS += HIGHLIGHT+tempS[pos:pos+len(word)]+RESET
    return newS
# ---------------------------------------------------
def display_tag_file(filename):
    f = open(filename, 'r', encoding='utf-8')
    s = f.read()
    return color_tag(s)

6530010921: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_21.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display0.0
['abc<red>rrr</>pkk\n', '
def<green>ggg</>ocr\n', '
xyz<blue>bbb</>abc\n', '
abc<red>rrr</>pf<reen>32mggg</>o<ed>31mrr</>z<blue>bbb</>abc']
[]
bytecount: {'code': 614, 'const': 477, 'code+const': 1091}
def red(s):
    return(RED+s+RESET)
# ---------------------------------------------------
def green(s):
    return(GREEN+s+RESET)
# ---------------------------------------------------
def blue(s):
    return(BLUE+s+RESET)
# ---------------------------------------------------
def highlight(s):
    return(HIGHLIGHT+s+RESET)
# ---------------------------------------------------
def color_text(s, color):
    if color.lower() == 'red':
        return(red(s))
    elif color.lower() == 'green':
        return(green(s))
    elif color.lower() == 'blue':
        return(blue(s))
    else:
        return(s)
# ---------------------------------------------------
def color_tag(s):
    startIdx = s.find('>')+1
    a = s[1:startIdx-1]
    closeIdx = s.rfind('<')
    return(color_text(s[startIdx:closeIdx],a))
# ---------------------------------------------------
def highlight_words(s, words):
    for text in words:
        out = ''
        startIdx = 0
        for i in range(len(s)-len(text)+1):
            if s[i:i+len(text)].lower() == text.lower():
                out +=  s[startIdx:i] + highlight(s[i:i+len(text)])
                startIdx = i + len(text)
        out += s[startIdx:]
        s = out
    return s
# ---------------------------------------------------
def display_tag_file(filename):
    s = ''
    fn = open(filename, 'r', encoding='utf-8')
    lines = fn.readlines()
    for line in lines:
        startIdx = 0
        openIdx  = line.find('<')
        closeIdx = -1
        while(openIdx!=-1):
            s = s+line[startIdx:openIdx]
            closeIdx=line.find('>',openIdx+1)
            closeIdx=line.find('>',closeIdx+1)
            colorText = color_tag(line[openIdx:closeIdx+1])
            s = s+colorText
            startIdx = closeIdx+1
            openIdx = line.find('<',startIdx)
        s = s + line[startIdx:]
    print(lines)
    fn.close()

6530011521: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display1.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 582, 'const': 549, 'code+const': 1131}
def red(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return RED+s+RESET
# ---------------------------------------------------
def green(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return GREEN+s+RESET
# ---------------------------------------------------
def blue(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return BLUE+s+RESET
# ---------------------------------------------------
def highlight(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return HIGHLIGHT+s+RESET
# ---------------------------------------------------
def color_text(s, color):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    if color.lower() == 'red':
      return(RED+s+RESET)
    elif color.lower() == 'blue':
      return(BLUE+s+RESET)
    elif color.lower() == 'green':
      return(GREEN+s+RESET)
    else:
      return(s)
# ---------------------------------------------------
def color_tag(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    if s.find('<red>') != -1:
      return(RED+s[s.find('<red>')+5:s.find('</>')]+RESET)
    if s.find('<blue>') != -1:
      return(BLUE+s[s.find('<blue>')+6:s.find('</>')]+RESET)
    if s.find('<green>') != -1:
      return(GREEN+s[s.find('<green>')+7:s.find('</>')]+RESET)
    else:
      return(s)
# ---------------------------------------------------
def highlight_words(s, words):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    if words == []:
      return s
    else:
      for i in words:
        s = s.replace(i,highlight(i))
      return s
# ---------------------------------------------------
def display_tag_file(filename):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    f = open(filename, "r", encoding='utf-8')
    for x in f:
        ss = x.split("</>")
        # print(ss)
        for i in range(len(ss)):
            if "<" in ss[i]:
                start = ss[i].find("<")
                ss[i] = ss[i][:start] + color_tag(ss[i][start:]+"</>")
        a = "".join(ss)
        if a[-1] == "\n":
          print(a[0:-1])
        else:
          print(a)

6530012121: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_21.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display1.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 824, 'const': 576, 'code+const': 1400}
def red(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return RED + s + RESET
# ---------------------------------------------------
def green(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return GREEN + s + RESET
# ---------------------------------------------------
def blue(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return BLUE + s + RESET
# ---------------------------------------------------
def highlight(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return HIGHLIGHT + s + RESET
# ---------------------------------------------------
def color_text(s, color):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    if color.lower() == 'red':
        return RED+s+RESET
    elif color.lower() == "green":
        return GREEN+s+RESET
    elif color.lower() == 'blue':
        return BLUE+s+RESET
    else:
        return s
# ---------------------------------------------------
def color_tag(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    if "<red>" in s:
        i1 = s.find("<red>")
        i2 = s.find("</>")
        text = s[i1+5:i2]
        s = s[:i1]+RED+text+RESET+s[i2+3:]
    if "<green>" in s:
        i1 = s.find("<green>")
        i2 = s.find("</>")
        text = s[i1+7:i2]
        s = s[:i1]+GREEN+text+RESET+s[i2+3:]
    if "<blue>" in s:
        i1 = s.find("<blue>")
        i2 = s.find("</>")
        text = s[i1+6:i2]
        s = s[:i1]+BLUE+text+RESET+s[i2+3:]
    return s
# ---------------------------------------------------
def highlight_words(s, words):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    text =""
    t1 = s
    num = 0
    if len(words) != 0:
        for i in range(len(words)):
            b = t1.lower().find(words[i].lower())
            while b != -1:
                num += b
                text += t1[num-b:num]
                num += len(words[i])
                text += HIGHLIGHT+t1[num-len(words[i]):num]+RESET
                b = t1[num:].lower().find(words[i].lower())
            text +=t1[num:]
            num = 0
            t1 = text
            text = ""
    return t1
# ---------------------------------------------------
def display_tag_file(filename):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    text = open(filename, 'r', encoding='utf-8').read()
    ftext = ''
    i = 0
    while (text.find('<',i) != -1):
      n = text.find('<',i)
      ftext += text[i:n]
      i = n+1
      m = text.find('<',i)
      ftext += color_tag(text[n:m+3])#</>
      i = m+3
    ftext += text[i:]
    print(ftext)

6530013821: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display0.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 330, 'const': 750, 'code+const': 1080}
def red(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return '\033[;31m'+ s +'\033[0m'
# ---------------------------------------------------
def green(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return '\033[;32m'+ s +'\033[0m'
# ---------------------------------------------------
def blue(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return '\033[;34m'+ s +'\033[0m'
# ---------------------------------------------------
def highlight(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return '\033[;103m'+ s +'\033[0m'
# ---------------------------------------------------
def color_text(s, color):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    i = color.lower()
    if i in ['red']:
      return '\033[;31m'+ s +'\033[0m'
    elif i in ['green']:
      return '\033[;32m'+ s +'\033[0m'
    elif i in ['blue']:
      return '\033[;34m'+ s +'\033[0m'
    else:
      return s
# ---------------------------------------------------
def color_tag(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    if '<red>' in s :
      return s.replace('<red>','\033[;31m').replace('</>','\033[0m')
    elif '<green>' in s :
      return s.replace('<green>','\033[;32m').replace('</>','\033[0m')
    elif '<blue>' in s :
      return s.replace('<blue>','\033[;34m').replace('</>','\033[0m')
# ---------------------------------------------------
def highlight_words(s, words):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    if words == []: return s
    for i in words:
      s = s.replace(i,highlight(i))
    return s
#ถ้ามันมีให้หาว่าอยู่indexไหน แล้วก็ให้highlight
#ข้ามให้ไปหาตัวนั้นในindexต่อไป(วนลูปไป)
# ---------------------------------------------------
def display_tag_file(filename):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    pass

6530014421: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_10.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display0.0
abcrrrpkk

defgggocr

xyzbbbabc

abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 684, 'const': 456, 'code+const': 1140}
def red(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return RED+s+RESET
# ---------------------------------------------------
def green(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return GREEN+s+RESET
# ---------------------------------------------------
def blue(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return BLUE+s+RESET
# ---------------------------------------------------
def highlight(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return HIGHLIGHT+s+RESET
# ---------------------------------------------------
def color_text(s, color):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    if color.upper()=='RED':
      return red(s)
    elif color.upper()=='GREEN':
      return green(s)
    elif color.upper()=='BLUE':
      return blue(s)
    else:
      return s
# ---------------------------------------------------
def color_tag(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    r=0
    g=0
    b=0
    res=0
    while r!=-1 or g!=-1 or b!=-1 or res!=-1:
      r=s.find('<red>')
      g=s.find('<green>')
      b=s.find('<blue>')
      res=s.find('</>')
      if r!=-1:
        s=s[:r]+RED+s[r+5:]
      elif g!=-1:
        s=s[:g]+GREEN+s[g+7:]
      elif b!=-1:
        s=s[:b]+BLUE+s[b+6:]
      elif res!=-1:
        s=s[:res]+RESET+s[res+3:]
    return s
# ---------------------------------------------------
def highlight_words(s, words):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    ss=s.upper()
    for e in words:
      ee=e.upper()
      if ee in ss:
        a=ss.find(ee)
        while a!=-1:
          s=s[:a]+highlight(s[a:a+len(e)])+s[a+len(e):]
          ss=s.upper()
          a=ss.find(ee,a+len(e)+len(highlight(s[a:a+len(e)])))
    return s
# ---------------------------------------------------
def display_tag_file(filename):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    a=open(filename, 'r', encoding='utf-8')
    for l in a:
      ans=color_tag(l)
      print(ans)
    a.close()

6530015021: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_21.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display1.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 966, 'const': 573, 'code+const': 1539}
def red(s):
    return RED+s+RESET
# ---------------------------------------------------
def green(s):
    return GREEN+s+RESET
# ---------------------------------------------------
def blue(s):
    return BLUE+s+RESET
# ---------------------------------------------------
def highlight(s):
    return HIGHLIGHT+s+RESET
# ---------------------------------------------------
def color_text(s, color):
    color = color.lower()
    if color == 'red':
      return RED+s+RESET
    if color == 'green':
      return GREEN+s+RESET
    if color == 'blue':
      return BLUE+s+RESET
    return s
# ---------------------------------------------------
def color_tag(s):
    pos1 = s.find('>')
    pos2 = s.find('<',pos1)
    if '<red>' in s:
      return RED+s[pos1+1:pos2]+RESET
    if '<green>' in s:
      return GREEN+s[pos1+1:pos2]+RESET
    if '<blue>' in s:
      return BLUE+s[pos1+1:pos2]+RESET
# ---------------------------------------------------
def highlight_words(s, words):
    cs = s.lower()
    allID = []
    if len(words) > 0:
      for word in words:
        word = word.lower()
        ID = []
        pos = cs.find(word)
        while pos != -1:
          ID.append([pos,s[pos:pos+len(word)]])
          pos = cs.find(word,pos+len(word))
        allID += ID
      allID.sort()
      #print(allID)
      out = s[:allID[0][0]]
      for i in range(len(allID)):
        pos = allID[i][0]
        word = allID[i][1]
        if i != len(allID)-1:
          next = allID[i+1][0]
          out += HIGHLIGHT+word+RESET+s[pos+len(word):next]
        else:
          out += HIGHLIGHT+word+RESET+s[pos+len(word):]
      return out
    else:
      return s
# ---------------------------------------------------
def display_tag_file(filename):
    all = ''
    fop = open(filename,'r',encoding='utf-8')
    for line in fop:
      all += line
    fop.close()
    consider = []
    i = 0
    allID = []
    while True:
      pos = all.find('<',i)
      next = all.find('</>',pos)
      if pos == -1 :break
      consider.append(all[pos:next+len('</>')])
      allID.append(i)
      allID.append(pos)
      i = next+len('</>')
      if i >= len(all):break
    color = []
    for code in consider:
      color.append(color_tag(code))
    out = ''
    for i in range(0,len(allID),2):
      d = i//2
      out += all[allID[i]:allID[i+1]] + color[d]
    if allID[-1]+len(consider[-1]) <= len(all):
      out += all[allID[-1]+len(consider[-1]):]
    print(out)

6530017321: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display0.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzorrzzbbbabc
[]
bytecount: {'code': 966, 'const': 649, 'code+const': 1615}
def red(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return RED+s+RESET
# ---------------------------------------------------
def green(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return GREEN+s+RESET
# ---------------------------------------------------
def blue(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return BLUE+ s +RESET
# ---------------------------------------------------
def highlight(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return HIGHLIGHT+ s +RESET
# ---------------------------------------------------
def color_text(s,color):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    color=color.lower()
    if color=='red':
        return RED+ s +RESET
    elif color=='blue':
        return BLUE+ s +RESET
    elif color=='green':
        return GREEN+ s +RESET
    else:
        return s
# ---------------------------------------------------
def color_tag(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    r = s.find('<red>')
    b = s.find('<blue>')
    g = s.find('<green>')
    end = s.rfind('</>')
    if not r == -1:
        return RED+ s[r+5:end:] +RESET    
    if not b == -1:
        return BLUE+ s[b+6:end:] +RESET
    if not g == -1:
        return GREEN+ s[g+7:end:] +RESET
# ---------------------------------------------------
def highlight_words(s, words):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    f = s
    for i in range(len(words)):
        rp = f.find(words[i])
        while not rp==-1:
            w = HIGHLIGHT+f[rp:rp+len(words[i]):]+RESET
            f = f[:rp]+w+f[rp+len(words[i]):]
            rp = f.find(words[i],rp+8)            
    return f
# ---------------------------------------------------
def display_tag_file(filename):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    f = open(filename, 'r', encoding='utf-8')
    for line in f:
        l=line.strip()
        r = l.find('<red>')
        b = l.find('<blue>')
        g = l.find('<green>')
        end = l.find('</>')
        while not r ==-1 or not b==-1 or not g==-1 :
           if not r == -1:
              l = l[:r]+ RED+ l[r+5:end:] +RESET+l[end:]
              end = l.find('</>',end+8)
              r = l.find('<red>')
              b = l.find('<blue>')
              g = l.find('<green>')
           if not b == -1:
              l = l[:b]+ BLUE+ l[b+6:end:] +RESET +l[end:]
              r = l.find('<red>')
              b = l.find('<blue>')
              g = l.find('<green>')
              end = l.find('</>',end+8)
           if not g == -1:
              l=l[:g]+ GREEN+ l[g+7:end:] +RESET+l[end:]
              r = l.find('<red>')
              b = l.find('<blue>')
              g = l.find('<green>')
              end = l.find('</>',end+8)
        end = l.find('</>')
        while not end==-1:
            l = l[:end]+l[end+3:]
            end = l.find('</>')
        print(l)
    f.close()
# ---------------------------------------------------

6530018021: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_10.0
['\x1b[;103m\x1b[;103m\x1b[;103m\x1b[;103mabc\x1b[0m\x1b[0m\x1b[0m\x1b[0mde\x1b[;103m\x1b[;103mfg\x1b[0m\x1b[0m\x1b[;103m\x1b[;103m\x1b[;103m\x1b[;103mabc\x1b[0m\x1b[0m\x1b[0m\x1b[0mabbcbf\x1b[;103m\x1b[;103mfg\x1b[0m\x1b[0mcd\x1b[;103m\x1b[;103m\x1b[;103m\x1b[;103mabc\x1b[0m\x1b[0m\x1b[0m\x1b[0maa\x1b[;103m\x1b[;103m\x1b[;103m\x1b[;103mabc\x1b[0m\x1b[0m\x1b[0m\x1b[0m']
test_highlight_20.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0mAbcAbbcbffGcd\x1b[;103mAbc\x1b[;103maAbbcbf\x1b[;103mfG\x1b[0maa\x1b[;103mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display0.0OSError("stdout's size exceeds 5000")
m[;31mrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbaba[;31mrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabb[;31mrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc[;31mrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbb[ ... (more)
[]
bytecount: {'code': 954, 'const': 560, 'code+const': 1514}
def red(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return RED + s + RESET
# ---------------------------------------------------
def green(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return GREEN + s + RESET
# ---------------------------------------------------
def blue(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return BLUE + s + RESET
# ---------------------------------------------------
def highlight(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return HIGHLIGHT + s + RESET
# ---------------------------------------------------
def color_text(s, color):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    colors = color.lower()
    if colors == 'red':
      return RED + s + RESET
    elif colors == 'green':
      return GREEN + s + RESET
    elif colors == 'blue':
      return BLUE + s + RESET
    else:
      return s
# ---------------------------------------------------
def color_tag(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    if '<red>' in s:
      n1 = s.find('<red>')
      s1 = s.replace('<red>','')
      n2 = s.find('</>')
      s2 = s1.replace('</>','')
      ds = s2[:n1] + RED + s2[n1:n2] + RESET + s2[n2:]
      return ds
    elif '<green>' in s:
      n1 = s.find('<green>')
      s1 = s.replace('<green>','')
      n2 = s.find('</>')
      s2 = s1.replace('</>','')
      ds = s2[:n1] + GREEN + s2[n1:n2] + RESET + s2[n2:]
      return ds
    elif '<blue>' in s:
      n1 = s.find('<blue>')
      s1 = s.replace('<blue>','')
      n2 = s.find('</>')
      s2 = s1.replace('</>','')
      ds = s2[:n1] + BLUE + s2[n1:n2] + RESET + s2[n2:]
      return ds
    else:
      pass
# ---------------------------------------------------
def highlight_words(s, words):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    for i in range(0,len(words)):
      n = s.count(words[i])
      for j in range(0,n):
        s = s.replace(words[i],highlight(words[i]))
    return s
# ---------------------------------------------------
def display_tag_file(filename):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    textu = open(filename, 'r', encoding='utf-8')
    text = textu.read()
    gcount = text.count('<green>')
    rcount = text.count('<red>')
    bcount = text.count('<blue>')
    gstart = '<green>'
    rstart = '<red>'
    bstart = '<blue>'
    end = '</>'
    for i in range(0,gcount-1):
      startgreen = text.find(gstart)
      endgreen = text.find(end,startgreen) + 3
      gword = text[startgreen+len(gstart):endgreen - 3]
      text = text.replace(text[startgreen:endgreen],GREEN + gword + RESET)
    for i in range(0,rcount):
      startred = text.find(rstart)
      endred = text.find(end,startred) + 3
      rword = text[startred+len(rstart):endred - 3]
      text = text.replace(text[startred:endred],red(rword))
    for i in range(0,bcount):
      startblue = text.find(bstart)
      endblue = text.find(end,startblue) + 3
      bword = text[startblue+len(bstart):endblue - 3]
      text = text.replace(text[startblue:endblue],blue(bword))
    print(text)
    textu.close()

6530019621: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_21.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display1.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 1818, 'const': 2924, 'code+const': 4742}
def red(s):
    RED = '\033[;31m'
    ansred = '\033[;31m'
    for e in s:
        ansred = ansred + e
    ansred = ansred + '\033[0m'
    return ansred
# ---------------------------------------------------
def green(s):
    GREEN = '\033[;32m'
    ansgreen = '\033[;32m'
    for e in s:
        ansgreen = ansgreen + e
    ansgreen = ansgreen + '\033[0m'
    return ansgreen
# ---------------------------------------------------
def blue(s):
    BLUE = '\033[;34m'
    ansblue = '\033[;34m'
    for e in s:
        ansblue = ansblue + e
    ansblue = ansblue + '\033[0m'
    return ansblue
# ---------------------------------------------------
def highlight(s):
    HIGHLIGHT = '\033[;103m'
    anshigh = '\033[;103m'
    for e in s:
        anshigh = anshigh + e
    anshigh = anshigh + '\033[0m'
    return anshigh
# ---------------------------------------------------
def color_text(s, color):
    if len(color) == 3:
        if color[0] in 'rR' and color[1] in 'eE' and color[2] in 'dD':
            RED = '\033[;31m'
            anscolred = red(s)
            return anscolred
    elif len(color) == 4:
        if color[0] in 'bB' and color[1] in 'lL' and color[2] in 'uU' and color[3] in 'eE':
            BLUE = '\033[;34m'
            anscolblue = blue(s)
            return anscolblue
    elif len(color) == 5:
        if color[0] in 'gG' and color[1] in 'rR' and color[2] in 'eE' and color[3] in 'eE' and color[4] in 'nN':
            GREEN = '\033[;32m'
            anscolgreen = green(s)
            return anscolgreen
    else:
        return s
# ---------------------------------------------------
def color_tag(s):
    i = 0
    ans = ''
    phak = ''
    posstart = []
    posend = []
    while i<len(s):
        phak = ''
        if s[i:i+5] == '<red>' and i+5<=len(s):
            posstart.append(i)
            i = i + 5
            while s[i:i+3] != '</>':
                phak = phak + s[i]
                i = i + 1
            i = i + 3
            posend.append(i)
            ans = ans + red(phak)
        elif s[i:i+7] == '<green>' and i+5<=len(s):
            posstart.append(i)
            i = i + 7
            while s[i:i+3] != '</>':
                phak = phak + s[i]
                i = i + 1
            i = i + 3
            posend.append(i)
            ans = ans + green(phak)
        elif s[i:i+6] == '<blue>' and i+5<=len(s):
            posstart.append(i)
            i = i + 6
            while s[i:i+3] != '</>':
                phak = phak + s[i]
                i = i + 1
            i = i + 3
            posend.append(i)
            ans = ans + blue(phak)
        else:
            ans = ans + s[i]
            i = i + 1
    return ans
# ---------------------------------------------------
def highlight_words(s, words):
    lens=len(s)
    lenw=len(words)
    poshighstart = []
    poshighend = []
    ans=''
    for i in range(lenw):
        j = 0
        while j < (lens-len(words[i])+1):
            if s[j:j+len(words[i])].lower() == words[i].lower():
                poshighstart.append(j)
                poshighend.append(j+len(words[i])-1)
                j = j + len(words[i])
            else:
                j = j + 1
    for i in range(lens):
        if i in poshighstart and i in poshighend :
            ans = ans + '\033[;103m' + s[i] + '\033[0m'
        elif i in poshighstart:
            ans = ans + '\033[;103m' + s[i]
        elif i in poshighend:
            ans = ans + s[i] + '\033[0m'
        else:
            ans = ans + s[i]
    return ans
# ---------------------------------------------------
def display_tag_file(filename):
    Rowfinished=''
    Rowfinished2=''
    file = open(filename,"r",encoding="utf-8")
    for Row in file:
        Rowfinished = Rowfinished + Row
    file.close()
    Rowfinished2 = color_tag(Rowfinished)
    print(Rowfinished2)
#---------------------------------------------------
def Test():        
    print('red text:', red('red text'), 'and normal text')
    print('green text:', green('green text'), 'and normal text')
    print('blue text:', blue('blue text'), 'and normal text')
    print('highlight text:', highlight('highlight text'), 'and normal text')
    print(red('red text'),green('green text'),blue('blue text'),highlight('highlight text'))
    print('\n')
    print(color_text('This is red text', 'red'))
    print(color_text('This is green text', 'GreeN'))
    print(color_text('This is blue text', 'BLUE'))
    print(color_text('This is yellow text', 'yellow'))
    print('\n')
    print(color_tag('<red>red text</>'))
    print(color_tag('<green>green text</>'))
    print(color_tag('<blue>blue text</>'))
    print(color_tag('<blue>blue text</> <red>red text</> <green>green text</>'))
    print('\n')
    t = 'a[3]มิใช่ลิสต์ คืนค่ามิใช่print =มิใช่เปรียบเทียบ รักมิใช่ดวงดาวที่พราวแสง'
    print(highlight_words(t,['มิใช่']))
    print(highlight_words(t,['ลิสต์']))
    print(highlight_words(t, []))
    w = ['print', 'ดาว', 'มิใช่']
    z = highlight_words(t, w)
    print(z) 
    w = ['[3]','ยบ']
    z = highlight_words(t, w)
    print(z) 
    t= 'KAKAKAKAKAKAKAKAKAKAK'
    print(highlight_words(t, ['kak']))
    #Bonus Highlight
    print('\n')
    print(red('Bonus Highlight'))
    print('\n')
    t= 'Good Morning Teacher How Are You Today Kak'
    print(highlight_words(t,['a']))
    print(highlight_words(t,['A','K']))
    print(highlight_words(t,['gooD']))
    print('\n')
    display_tag_file("มหาจุฬาลงกรณ์-tag.txt")
    #Bonus File
    print('\n')
    print(red('Bonus File'))
    print('\n')
    display_tag_file("ไอเชนอย่างกากเลยนิ.txt")

6530020121: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display1.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 670, 'const': 633, 'code+const': 1303}
def red(s):
    return RED + s + RESET
# ---------------------------------------------------
def green(s):
    return GREEN + s + RESET
# ---------------------------------------------------
def blue(s):
    return BLUE + s + RESET
# ---------------------------------------------------
def highlight(s):
    return HIGHLIGHT + s + RESET
# ---------------------------------------------------
def color_text(s, color):
    out = ""
    color = color.lower()
    if color == 'red':
        out = red(s)
    elif color == 'blue':
        out = blue(s)
    elif color == 'green':
        out = green(s)
    else:
        out = s
    return out
# ---------------------------------------------------
def color_tag(s):
    color_s = s.find('<',0)
    color_f = s.find('>',0)
    ending = s.find('</>',color_f)
    color = s[1:color_f]
    word = s[color_f+1:ending]
    if color == 'red':
        out = red(word)
    elif color == 'blue':
        out = blue(word)
    elif color == 'green':
        out = green(word)
    else:
        out = word
    return out
# ---------------------------------------------------
def highlight_words(s, words):
    out = ''
    for k in words:
        out = ''
        i = 0
        l = len(k)
        while k in s[i:]:
            temp1 = s.find(k,i)
            out += s[i:temp1]
            out += highlight(k)
            i = temp1 + l
        out += s[i:]
        s = out
    if len(out) == 0:
        return s
    else:
        return out
# ---------------------------------------------------
def display_tag_file(filename):
    text = ''
    out = ''
    op = open(filename,'r',encoding='utf-8')
    for line in op:
        text += line
    op.close()
    i = 0
    while True:
        st_c = text.find('<',i)
        en_c = text.find('</>',st_c)
        col_word = text[st_c:en_c+3]
        dcol_word = color_tag(col_word)
        out += text[i:st_c]
        out += dcol_word
        i = en_c+3
        if en_c ==-1:
            break
    if text[-3:] == '</>':
        pass
    else:
        out += text[-1:]
    print(out)

6530021821: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display1.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 576, 'const': 472, 'code+const': 1048}
def red(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    word = RED + s + RESET
    return word
# ---------------------------------------------------
def green(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    word = GREEN + s + RESET
    return word
# ---------------------------------------------------
def blue(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    word = BLUE + s + RESET
    return word
# ---------------------------------------------------
def highlight(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    word = HIGHLIGHT + s + RESET
    return word
# ---------------------------------------------------
def color_text(s, color):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    if color.lower() == 'red':
      w = red(s)
    elif color.lower() == 'green':
      w = green(s)
    elif color.lower() == 'blue':
      w = blue(s)
    elif color.lower() == 'highlight':
      w = highlight(s)
    else:
      w = s
    return w
# ---------------------------------------------------
def color_tag(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    word = s.split('>')
    w = word[1][:-2]
    w = w.strip()
    col = word[0][1:]
    return color_text(w, col)
# ---------------------------------------------------
def highlight_words(s, words):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    for i in words:
      x = 0
      while x!=-1:
        x = s.find(i , x , len(s))
        if x==-1:
          break
        s = s[0:x] + highlight(i) + s[(x+len(i)):]
        x += len(highlight(i))
    return s
# ---------------------------------------------------
def display_tag_file(filename):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    infile = open(filename, 'r', encoding='utf-8')
    PromptKurbMae=''
    for line in infile:
      k = []
      n = ''
      lst = line.split('</>')
      for i in lst:
        x = i.split('<')
        k+= x
      for i in k :
        if '>' in i: 
          b = '<' + i + '</>'
          b = color_tag(b)
          n+=b
        else:
          n+=i
      PromptKurbMae += n
    infile.close()
    return print(PromptKurbMae)

6530022421: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_10.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display0.0NameError("name 'colortag' is not defined")
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 646, 'const': 535, 'code+const': 1181}
def red(s):
    k = RED + s + RESET
    return k
# ---------------------------------------------------
def green(s):
    k = GREEN + s + RESET
    return k
# ---------------------------------------------------
def blue(s):
    k = BLUE + s + RESET
    return k
# ---------------------------------------------------
def highlight(s):
    k = HIGHLIGHT + s + RESET
    return k
# ---------------------------------------------------
def color_text(s, color):
    if color == 'red':
        k = red(s)
    elif color == 'green':
        k = green(s)
    elif color == 'blue':
        k = blue(s)
    else:
        k = s
    return k
# ---------------------------------------------------
def color_tag(s):
    if s[0:5] == '<red>' and s[-3:] == '</>':
        k = red(s[5:-3])
    if s[0:7] == '<green>' and s[-3:] == '</>':
        k = green(s[7:-3])
    if s[0:6] == '<blue>' and s[-3:] == '</>':
        k = blue(s[6:-3])
    return k
# ---------------------------------------------------
def highlight_words(s, words):
    k = ''
    Start = []
    End = []
    for i in range(len(words)):
        j = 0
        while j < (len(s) - len(words) + 1):
            if s[j:(j + len(words))] == words[i]:
                Start.append(j)
                End.append(j+len(words) - 1)
                j += len(words)
            else:
                j += 1
    for i in range(len(s)):
        if i in Start:
            k += HIGHLIGHT + s[i]
        elif i in End:
            k += RESET
        else:
            k += s[i]
    return k
# ---------------------------------------------------
def display_tag_file(filename):
    k = ''
    e = ''
    fn = open(filename,'r',encoding='utf-8')
    for line in fn:
        k = str(colortag(line))
        e += k + '/n'
    fn.close()
    return e

6530023021: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_21.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display1.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 648, 'const': 570, 'code+const': 1218}
def red(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return RED + s + RESET
# ---------------------------------------------------
def green(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return GREEN + s + RESET
# ---------------------------------------------------
def blue(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return BLUE + s + RESET
# ---------------------------------------------------
def highlight(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return HIGHLIGHT + s + RESET
# ---------------------------------------------------
def color_text(s, color):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    color = color.lower() #แปลงให้เป็นตัวเล็กให้หมด
    if color == "red":
        return red(s)
    elif color == "green":
        return green(s)
    elif color == "blue":
        return blue(s)
    else:
        return s
# ---------------------------------------------------
def color_tag(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    if s.find("red") == 1:
        return red(s[5:-3:1])
    if s.find("green") == 1:
        return green(s[7:-3:1])
    if s.find("blue") == 1:
        return blue(s[6:-3:1])
# ---------------------------------------------------
def highlight_words(s, words):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    for i in range(len(words)):
        ans = ""
        c = 0
        a = s.lower() 
        while a.find(words[i].lower(),c) != -1:
            f = a.find(words[i].lower(),c) #ทำให้ไม่ต้องเรียกหาบ่อย
            ans += s[c:f:1] + highlight(s[f:f+len(words[i])]) #ไม่ไฮไลท์ + ไฮไลท์
            c = f + len(words[i]) #กำหนดจุดเริ่มต้นใหม่
        ans += s[c::] # + ที่เหลือที่ไม่ไฮไลท์
        s = ans
    return s
# ---------------------------------------------------
def display_tag_file(filename):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    fn = open(filename, 'r', encoding='utf-8')
    ans = ""
    answer = ""
    for line in fn:
      ans += line #ทำให้เป็น str
    c = 0
    while ans.find("<",c) != -1:
        x = ans.find("<",c)
        answer += ans[c:x:1]
        c = x + 1 #เริ่มหา < อีกตัว
        y = ans.find("<",c)
        answer += color_tag(ans[x:y+3:1])
        c = y + 3 #เริ่มหาตัวใหม่
    answer += ans[c:]
    fn.close()
    return print(answer)

6530024721: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_10.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mgabc\x1b[0mabcabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mgabc\x1b[0mcdaa\x1bcaa[;103mabc\x1b[0m']
test_highlight_20.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mgAbc\x1b[0mAbcAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display1.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 710, 'const': 658, 'code+const': 1368}
def red(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    out = ''
    for e in s :
        out += RED + e + RESET
    return out    
# ---------------------------------------------------
def green(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    out = ''
    for e in s :
        out += GREEN + e + RESET
    return out  
# ---------------------------------------------------
def blue(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    out = ''
    for e in s :
        out += BLUE + e + RESET
    return out  
# ---------------------------------------------------
def highlight(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    out = ''
    for e in s :
        out += HIGHLIGHT + e + RESET
    return out  
# ---------------------------------------------------
def color_text(s, color):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    color = color.lower()
    if color == 'red' :
        return red(s)
    elif color == 'green' :
        return green(s)
    elif color == 'blue' :
        return blue(s)
    else :
        return s            
# ---------------------------------------------------
def color_tag(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    color = ''
    text = ''
    k = []
    for e in s :
        k.append(e)
    v = k.index('>')
    for e in k[1:v] :
        color += e
    for e in k[v+1:len(s)-3] :
        text += e
    out = color_text(text,color)        
    return out
# ---------------------------------------------------
def highlight_words(s, words):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    j = 0
    while j < len(words) :
        out = s.replace(words[j],highlight(words[j]))
        j += 1
    return out    
# ---------------------------------------------------
def display_tag_file(filename):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    out = '' 
    im = open(filename, 'r',encoding='utf-8')
    for line in im :
        for i in range(len(line)) :
            if line[i:i+5] == '<red>' :
                line = line.replace(line[i:i+5],RED)
            elif line[i:i+7] == '<green>' :
                line = line.replace(line[i:i+7],GREEN) 
            elif line[i:i+6] == '<blue>' :
                line = line.replace(line[i:i+6],BLUE) 
            elif line[i:i+3] == '</>' :
                line = line.replace(line[i:i+3],RESET)
        out += line                 
    im.close()
    return print(out)

6530025321: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display0.0FileNotFoundError("No such file or directory: 'มหาจุฬาลงกรณ์-tag.txt'")
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 1156, 'const': 1113, 'code+const': 2269}
def color_tag3(c,t):
    if c == 'red':
        ans = RED + t + '\033[0m'
    elif c == 'green':
        ans = GREEN + t + '\033[0m'
    elif c == 'blue':
        ans = BLUE + t + '\033[0m'
    else :
        ans = t
    return(ans)
#----------------------------------------------------
def color_tag2(s):
    color = ""
    color2 = ""
    text = []
    for e in range(len(s)):
        if s[e] == '<':
            sta = int(e)
        elif s[e] == '>':
            sto = int(e)
            color += s[sta+1:sto]
    for k in color:
        if k == '/':
            color2 += ' '
        else:
            color2 += k
    color2 = color2.strip()
    color2 = color2.split()
    for i in range(len(s)):
        if s[i] == '>':
            statext = int(i)
        elif s[i] == '<':
            if s[i+1] in '/':
                stotext = int(i)
                text.append(s[statext+1:stotext])
    for q in range(len(text)):
        s = s.replace('<'+str(color2[q])+'>'+str(text[q])+'</>',color_tag3(str(color2[q]),str(text[q])))
    return(s)
#-----------------------------------------------------------------------------------------------------------
# ตัวแปรต่อไปนี้เป็นตัวแปรที่กำหนดค่าสีเพื่อเอาไว้ใช้ในโปรแกรม (ห้ามแก้ไข)
def red(s):
    ans = RED + s + '\033[0m'
    return(ans)
# ---------------------------------------------------
def green(s):
    ans = GREEN + s + '\033[0m'
    return(ans)
# ---------------------------------------------------
def blue(s):
    ans = BLUE + s + '\033[0m'
    return(ans)
# ---------------------------------------------------
def highlight(s):
    ans = HIGHLIGHT + s + '\033[0m'
    return(ans)
# ---------------------------------------------------
def color_text(s, color):
    color = color.lower()
    if color == 'red':
        ans = RED + s + '\033[0m'
    elif color == 'green':
        ans = GREEN + s + '\033[0m'
    elif color == 'blue':
        ans = BLUE + s + '\033[0m'
    else :
        ans = s
    return(ans)
# ---------------------------------------------------
def color_tag(s):
    color = ""
    text = ""
    for e in range(len(s)):
        if s[e] == '>':
            color += s[1:e]
            break
    x = s.find('>')
    y = s.find('<',x)
    text += s[x+1:y]
    if color == 'red':
        ans = RED + text + '\033[0m'
    elif color == 'green':
        ans = GREEN + text + '\033[0m'
    elif color == 'blue':
        ans = BLUE + text + '\033[0m'
    else :
        ans = text
    return(ans)
# ---------------------------------------------------
def highlight_words(s, words):
    ans = ""
    ying = []
    if len(words) == 0:
        return (s)
    else:
        for i in range(len(words)):
            e = 0
            while e <= len(s)-1:
                if len(words) != 0:
                    if s[e] == words[i][0]:
                        if s[e:e+len(words[i])] == words[i]:
                            hi = HIGHLIGHT + words[i] + '\033[0m'
                            ans += hi
                            e += len(words[i])
                        else:
                            ans += s[e]
                            e += 1
                    else:
                        ans += s[e]
                        e += 1
                else:
                    ans += s[e]
                    e += 1
            s = ans
            ying.append(s)
            ans = ""
    return(ying[len(words)-1])
# ---------------------------------------------------
def display_tag_file(filename):
    ans = ""
    exp = ''
    fn = open('มหาจุฬาลงกรณ์-tag.txt', 'r', encoding='utf-8')
    for line in fn:
        ans = str(color_tag2(line))
        exp += ans + '\n'
    fn.close()  
    return (print(exp))

6530026021: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_10.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display1.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 584, 'const': 591, 'code+const': 1175}
def red(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return RED+s+RESET
# ---------------------------------------------------
def green(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return GREEN+s+RESET
# ---------------------------------------------------
def blue(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return BLUE+s+RESET
# ---------------------------------------------------
def highlight(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return HIGHLIGHT+s+RESET
# ---------------------------------------------------
def color_text(s, color):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    tuna = color.lower()
    if tuna == 'red' :
        return red(s)
    if tuna == 'green' :
        return green(s)
    if tuna == 'blue' :
        return blue(s)
    else :
        return s
# ---------------------------------------------------
def color_tag(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    if s[1] == 'r' :
        return red(s[5:-3:])
    if s[1] == 'g' :
        return green(s[7:-3:])
    if s[1] == 'b' :
        return blue(s[6:-3:])
# ---------------------------------------------------
def highlight_words(s, words):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    for i in range(len(words)) :
      f =  s.replace(words[i], highlight(words[i]))
    return f
# ---------------------------------------------------
def display_tag_file(filename):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    tee = ''
    free = open(filename, 'r',encoding = 'utf-8')
    for police in free :
      for i in range(len(police)) :
        if police[i:i+5:] == "<red>" :
          police = police.replace(police[i:i+5],RED)
        if police[i:i+6:] == "<blue>" :
          police = police.replace(police[i:i+6],BLUE)
        if police[i:i+7:] == "<green>" :
          police = police.replace(police[i:i+7],GREEN)
        if police[i:i+3:] == "</>" :
          police = police.replace(police[i:i+3],RESET)
      tee += police
    free.close()
    print(tee)

6530027621: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_21.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display1.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 1244, 'const': 1033, 'code+const': 2277}
def color_tag3(c,t):
    if c == 'red':
        ans = RED + t + '\033[0m'
    elif c == 'green':
        ans = GREEN + t + '\033[0m'
    elif c == 'blue':
        ans = BLUE + t + '\033[0m'
    else :
        ans = t
    return(ans)
#----------------------------------------------------
def color_tag2(s):
    color = ""
    color2 = ""
    text = []
    for e in range(len(s)):
        if s[e] == '<':
            sta = int(e)
        elif s[e] == '>':
            sto = int(e)
            color += s[sta+1:sto]
    for k in color:
        if k == '/':
            color2 += ' '
        else:
            color2 += k
    color2 = color2.strip()
    color2 = color2.split()
    for i in range(len(s)):
        if s[i] == '>':
            statext = int(i)
        elif s[i] == '<':
            if s[i+1] in '/':
                stotext = int(i)
                text.append(s[statext+1:stotext])
    for q in range(len(text)):
        s = s.replace('<'+str(color2[q])+'>'+str(text[q])+'</>',color_tag3(str(color2[q]),str(text[q])))
    return(s)
#-----------------------------------------------------------------------------------------------------------
# ตัวแปรต่อไปนี้เป็นตัวแปรที่กำหนดค่าสีเพื่อเอาไว้ใช้ในโปรแกรม (ห้ามแก้ไข)
def red(s):
    ans = RED + s + '\033[0m'
    return(ans)
# ---------------------------------------------------
def green(s):
    ans = GREEN + s + '\033[0m'
    return(ans)
# ---------------------------------------------------
def blue(s):
    ans = BLUE + s + '\033[0m'
    return(ans)
# ---------------------------------------------------
def highlight(s):
    ans = HIGHLIGHT + s + '\033[0m'
    return(ans)
# ---------------------------------------------------
def color_text(s, color):
    color = color.lower()
    if color == 'red':
        ans = RED + s + '\033[0m'
    elif color == 'green':
        ans = GREEN + s + '\033[0m'
    elif color == 'blue':
        ans = BLUE + s + '\033[0m'
    else :
        ans = s
    return(ans)
# ---------------------------------------------------
def color_tag(s):
    color = ""
    text = ""
    for e in range(len(s)):
        if s[e] == '>':
            color += s[1:e]
            break
    x = s.find('>')
    y = s.find('<',x)
    text += s[x+1:y]
    if color == 'red':
        ans = RED + text + '\033[0m'
    elif color == 'green':
        ans = GREEN + text + '\033[0m'
    elif color == 'blue':
        ans = BLUE + text + '\033[0m'
    else :
        ans = text
    return(ans)
# ---------------------------------------------------
def highlight_words(s, words):
    ans = ""
    ying = []
    kin = ""
    s2 = s.lower()
    for k in range(len(words)):
        kin += (words[k]+" ")
    kin2 = kin.lower()
    words2 = kin2.split()
    if len(words) == 0:
        return (s)
    else:
        for i in range(len(words)):
            e = 0
            while e <= len(s)-1:
                if len(words) != 0:
                    if s2[e] == words2[i][0]:
                        if s2[e:e+len(words2[i])] == words2[i]:
                            hi = HIGHLIGHT + s[e:e+len(words[i])] + '\033[0m'
                            ans += hi
                            e += len(words[i])
                        else:
                            ans += s[e]
                            e += 1
                    else:
                        ans += s[e]
                        e += 1
                else:
                    ans += s[e]
                    e += 1
            s2 = ans.lower()
            s = ans
            ying.append(s)
            ans = ""
    return(ying[len(words)-1])
# ---------------------------------------------------
def display_tag_file(filename):
    ans = ""
    exp = ''
    fn = open(filename, 'r', encoding='utf-8')
    for line in fn:
        ans = str(color_tag2(line))
        exp += ans 
    fn.close()   
    return (print(exp))

6530028221: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display0.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 600, 'const': 379, 'code+const': 979}
def red(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return RED+str(s)+RESET
# ---------------------------------------------------
def green(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return GREEN+str(s)+RESET
# ---------------------------------------------------
def blue(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return BLUE+str(s)+RESET
# ---------------------------------------------------
def highlight(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return HIGHLIGHT+str(s)+RESET
# ---------------------------------------------------
def color_text(s, color):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    if str(color).lower() == 'red' :
        return red(str(s))
    elif str(color).lower() == 'green' :
        return green(str(s))
    elif str(color).lower() == 'blue' :
        return blue(str(s))
    else :
        return str(s)
# ---------------------------------------------------
def color_tag(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    if s[s.index('<')+1:s.index('>'):] == 'red' :
        return red(s[s.index('>')+1:-3:])
    elif s[s.index('<')+1:s.index('>'):] == 'green' :
        return green(s[s.index('>')+1:-3:])
    elif s[s.index('<')+1:s.index('>'):] == 'blue' :
        return blue(s[s.index('>')+1:-3:])
# ---------------------------------------------------
def highlight_words(s, words):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    result=''
    read=0
    while read <= len(s)-1 :
        a=[]
        for i in range(len(words)) :
            if s[read:read+len(words[i])] == words[i] :
                result+= highlight(words[i])
                read+=len(words[i])
                a.append(1)
                break
            else :
                a.append(0)
        if not 1 in a :
            result+= s[read]
            read+=1
    return result
# ---------------------------------------------------
def display_tag_file(filename):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    pass

6530029921: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_10.0
['\x1b[;103m\x1b[;103m\x1b[;103m\x1b[;103mabc\x1b[0m\x1b[0m\x1b[0m\x1b[0mde\x1b[;103m\x1b[;103mfg\x1b[0m\x1b[0m\x1b[;103m\x1b[;103m\x1b[;103m\x1b[;103mabc\x1b[0m\x1b[0m\x1b[0m\x1b[0mabbcbf\x1b[;103m\x1b[;103mfg\x1b[0m\x1b[0mcd\x1b[;103m\x1b[;103m\x1b[;103m\x1b[;103mabc\x1b[0m\x1b[0m\x1b[0m\x1b[0maa\x1b[;103m\x1b[;103m\x1b[;103m\x1b[;103mabc\x1b[0m\x1b[0m\x1b[0m\x1b[0m']
test_highlight_20.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103m\x1b[;103mabc\x1b[0m\x1b[0maa\x1b[;103m\x1b[;103mabc\x1b[0m\x1b[0m']
test_display0.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 972, 'const': 2287, 'code+const': 3259}
def red(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return str('\033[;31m'+s+'\033[0m')
# ---------------------------------------------------
def green(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return str('\033[;32m'+s+'\033[0m')
# ---------------------------------------------------
def blue(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return str('\033[;34m'+s+'\033[0m')
# ---------------------------------------------------
def highlight(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return str('\033[;103m'+s+'\033[0m')
# ---------------------------------------------------
def color_text(s,color):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    if color.lower() == "red":
        return red(s)
    elif color.lower() == "green":
        return green(s)
    elif color.lower() == "blue":
        return blue(s)
    else:
        return s
# ---------------------------------------------------
def color_tag(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    if "<red>" in s :
        s = s.replace("<red>","")
        s = s.replace("</>","")
        return color_text(s,"red")
    elif "<green>" in s:
        s = s.replace("<green>","")
        s = s.replace("</>","")
        return color_text(s,"green")
    elif "<blue>" in s:
        s = s.replace("<blue>","")
        s = s.replace("</>","")
        return color_text(s,"blue")
    else:
        return s
# ---------------------------------------------------
def highlight_words(s, words):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    cnt = 0
    h_list = []
    n_list = []
    for j in words:
        for i in range(len(s)-len(j)+1):
            if s[i:len(j)+i].lower() == j.lower():
                y = highlight(s[i:len(j)+i])
                x = s[i:len(j)+i]
                h_list.append(y)
                n_list.append(x)
                cnt+=1
    for i in range(cnt):
        s = s.replace(n_list[i],h_list[i])
    return s
# ---------------------------------------------------
def display_tag_file(filename):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    f = open(filename,'r', encoding='utf-8')
    p='' #เก็บแต่ละบรรทัดมาไว้ในสตริงเดียว
    for i in f:
        p+=i
    l = p.replace("<red>",",`$<red>").replace("<blue>",",`$<blue>").replace("<green>",",`$<green>").replace("</>","</>,`$").split(",`$") #replace และแยกด้วย ,
    n = '' #คืนค่าแต่ละบรรทัด
    for i in l:
        if "\n" not in i:
            n += color_tag(i)
        else:
            n += color_tag(i)
            print(n,end ="") #ต่อเลย
            n = ''
    print()
def test():
    print('red text:', red('red text'), 'and normal text') 
    print('green text:', green('green text'), 'and normal text') 
    print('blue text:', blue('blue text'), 'and normal text')
    print('highlight text:', highlight('highlight text'), 'and normal text')
    print(color_text('This is red text', 'red')) 
    print(color_text('This is green text', 'GreeN')) 
    print(color_text('This is blue text', 'BLUE')) 
    print(color_text('This is yellow text', 'yellow')) 
    print(color_tag('<red>red text</>')) 
    print(color_tag('<green>green text</>'))
    print(color_tag('<blue>blue text</>')) 
    t = 'a[3]มิใช่ลิสต์ คืนค่ามิใช่print =มิใช่เปรียบเทียบ รักมิใช่ดวงดาวที่พราวแสง'
    print(highlight_words(t,['มิใช่'])) 
    print(highlight_words(t,['ลิสต์'])) 
    print(highlight_words(t, [])) 
    w = ['print', 'ดาว', 'มิใช่']
    z = highlight_words(t, w)
    print(z)
    display_tag_file('มหาจุฬาลงกรณ์-tag.txt')

6530030421: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display0.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc<red>rrr</>pf<green>ggg</>o<red>rr</>z<blue>bbb</>abc
[]
bytecount: {'code': 624, 'const': 802, 'code+const': 1426}
def red(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return '\033[;31m' + s + '\033[0m'
# ---------------------------------------------------
def green(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return '\033[;32m' + s + '\033[0m' 
# ---------------------------------------------------
def blue(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return '\033[;34m' + s + '\033[0m'
# ---------------------------------------------------
def highlight(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return '\033[;103m' + s + '\033[0m'
# ---------------------------------------------------
def color_text(s, color):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    color = color.lower()
    if color == "red":
      return red(s)
    elif color == "green":
      return green(s)
    elif color == "blue":
      return blue(s)
    else :
      return s
# ---------------------------------------------------
def color_tag(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    if s[:5] == "<red>":
      return red(s[5:-3])
    if s[:7] == "<green>":
      return green(s[7:-3])
    if s[:6] == "<blue>":
      return blue(s[6:-3])
# ---------------------------------------------------
def highlight_words(s, words):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
     for i in words:
      ind = 0
      next = len(i)
      while s.find(i, ind) != -1:  
        s = s[:s.find(i, ind)] + highlight(s[s.find(i, ind):s.find(i, ind) + next]) + s[s.find(i, ind) + next:]
        ind = s.find(i, ind) + next
     return s
# ---------------------------------------------------
def display_tag_file(filename):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    f = open(filename, 'r', encoding='utf-8')
    for line in f:
      ind = 0
      newline = ""
      while line.find("<", ind) != -1 :
        start = line.find("<", ind)
        end = line.find("<", start + 1)
        s = line[start:end + 3]
        newline += line[ind:start] + color_tag(s)
        ind = end + 3
      if "\n" in line:
        newline += line[ind:-2]
      else :
        newline += line
      print(newline)
    f.close()
#Test
#1 --> Checked 
#print('red text:', red('red text'), 'and normal text')
#print('green text:', green('green text'), 'and normal text')
#print('blue text:', blue('blue text'), 'and normal text')	
#print('highlight text:', highlight('highlight text'), 'and normal text')
#2 --> Checked
#print(color_text('This is red text', 'red'))
#rint(color_text('This is green text', 'GreeN'))	
#print(color_text('This is blue text', 'BLUE'))
#print(color_text('This is yellow text', 'yellow'))
#3 --> Checked
#print(color_tag('<red>red text</>'))
#print(color_tag('<green>green text</>'))
#print(color_tag('<blue>blue text</>'))
#4 --> Checked
#t = 'a[3]มิใช่ลิสต์ คืนค่ามิใช่print =มิใช่เปรียบเทียบ รักมิใช่ดวงดาวที่พราวแสง'
#print(highlight_words(t, ['มิใช่']))
#print(highlight_words(t,['ลิสต์']))	
#print(highlight_words(t, []))	
#w = ['print', 'ดาว', 'มิใช่']
#z = highlight_words(t, w)
#print(z)
#5 --> 
##display_tag_file('มหาจุฬาลงกรณ์-tag.txt')

6530031021: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_10.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display0.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 424, 'const': 855, 'code+const': 1279}
def red(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return('\033[;31m'+str(s)+'\033[0m')
# ---------------------------------------------------
def green(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return('\033[;32m'+str(s)+'\033[0m')
# ---------------------------------------------------
def blue(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return('\033[;34m'+str(s)+'\033[0m')
# ---------------------------------------------------
def highlight(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return('\033[;103m'+str(s)+'\033[0m')
# ---------------------------------------------------
def color_text(s, color):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    if color.lower() == "red" :
        return(red(s))
    elif color.lower() == "blue" :
        return(blue(s))
    else :
        if color.lower() == "green" :
            return(green(s))
# ---------------------------------------------------
def color_tag(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    if "d" in s :
        return(red(s[-4:4:-1][::-1]))
    elif "g" in s :
        return(green(s[-4:6:-1][::-1]))
    elif "b" in s :
        return(blue(s[-4:5:-1])[::-1])
# ---------------------------------------------------
def highlight_words(s, words):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    for i in range(0,len(words)) :
        s = s.replace(words[i],'\033[;103m'+ str(words[i]) + '\033[0m')
        return(s)
# ---------------------------------------------------
def display_tag_file(filename):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    X = open(filename, 'r', encoding='utf-8')
    reset ='\033[0m'  
    r = '\033[;31m' 
    g = '\033[;32m'
    b = '\033[;34m'
    highlight = '\033[;103m'

6530032721: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_10.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display0.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfabcgggoabcrrzabcbbbabc
[]
bytecount: {'code': 956, 'const': 882, 'code+const': 1838}
def red(s):
    output = '\033[;31m' + s + '\033[0m'
    return(output)
# ---------------------------------------------------
def green(s):
    output = '\033[;32m' + s + '\033[0m'
    return(output)
# ---------------------------------------------------
def blue(s):
    output = '\033[;34m' + s + '\033[0m'
    return(output)
# ---------------------------------------------------
def highlight(s):
    output = '\033[;103m' + s + '\033[0m'
    return(output)
# ---------------------------------------------------
def color_text(s, color):
    c = color.lower()
    if c == 'red' :
        output = red(s)
    elif c == 'green' :
        output = green(s)
    elif c == 'blue' :
        output = blue(s)
    else :
        output = s
    return(output)
# ---------------------------------------------------
def color_tag(s):
    i1 = s.find('>')
    i2 = s.find('<',i1)
    string = s[i1+1:i2]
    c = s[1:i1]
    if c == 'red' :
        output = red(string)
    elif c == 'green' :
        output = green(string)
    elif c == 'blue' :
        output = blue(string)
    else :
        output = string
    return(output)
# ---------------------------------------------------
def highlight_words(s, words):
    s1 = s.lower()
    output = s
    ind = []
    for j in range(len(words)) :
        for i in range(len(s) - len(words[j])) :
            if s1[i:i+len(words[j])] == words[j].lower() :
                ind.append([i,s[i:i+len(words[j])]])
    ind.sort()
    ind.append([-1,''])
    output = s[0:ind[0][0]]
    for i in range(len(ind)-1) :
        output += '\033[;103m' + ind[i][1] + '\033[0m' + s[ind[i][0]+len(ind[i][1]):ind[i+1][0]]
    output += s[-1]
    return(output)
# ---------------------------------------------------
def display_tag_file(filename):
    fn = open(filename, 'r', encoding='utf-8')
    for line in fn :
        if '<' in line :
            ind = []
            index = []
            for i in range(len(line)-1) :
                if line[i] == '<' :
                    ind.append(i)
            for i in range(1,len(ind),2) :
                ind[i] += 3
            for i in range(0,len(ind),2) :
                index.append([ind[i],ind[i+1]])
            index.append([-1,-1])
            out = ''
            for i in range(len(index)-1) :
                out += line[0:index[0][0]]
                out += color_tag(line[index[i][0]:index[i][1]]) + line[index[i][1]:index[i+1][0]]
            print(out)
        else :
            print(line)            
    fn.close()

6530033321: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0
['\x1b[;103mabcBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103maAbc\x1b[0mAbbcbf\x1b[;103mfgG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display0.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 576, 'const': 585, 'code+const': 1161}
def red(s):
    return RED + s + RESET
# ---------------------------------------------------
def green(s):
    return GREEN + s + RESET
# ---------------------------------------------------
def blue(s):
    return BLUE + s + RESET
# ---------------------------------------------------
def highlight(s):
    return HIGHLIGHT + s + RESET
# ---------------------------------------------------
def color_text(s, color):
    if color.lower() == 'red':
        return red(s)
    elif color.lower() == 'green':
        return green(s)
    elif color.lower() == 'blue':
        return blue(s)
    else:
        return s
# ---------------------------------------------------
def color_tag(s):
    x = ''
    for i in s[1:-3]:
        if 'a' <= i <= 'z':
            x += i
        else:
            x += ' '
    x = x.split()
    ss = ''
    for i in range(len(x)):
        ss += "".join(x)
    for e in range(len(x)):
        return color_text(ss, str(x[0]))
# ---------------------------------------------------
def highlight_words(s, words):
    out = s
    for x in words:  
        asd = ''
        y = 0
        while y < len(out):
            if out[y:y+len(x)].lower() == x.lower():
                asd += highlight(x)
                y += len(x)
            else:
                asd += out[y]
                y += 1
        out = asd
    return out
# ---------------------------------------------------
def display_tag_file(filename):
    fn = open(filename, 'r', encoding='utf-8')
    out = ''
    line = fn.readline()
    for line in fn:
        line.replace('<red>', RED)
        line.replace('<green>', GREEN)
        line.replace('<blue>', BLUE)
        line.replace('</>', RESET)
    out += line
    fn.close()
    return out

6530035621: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_21.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display1.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 970, 'const': 1365, 'code+const': 2335}
def red(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    x = "\033[;31m" + s + "\033[0m"
    return x
# ---------------------------------------------------
def green(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    x = "\033[;32m" + s + "\033[0m"
    return x
# ---------------------------------------------------
def blue(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    x = "\033[;34m" + s + "\033[0m"
    return x
# ---------------------------------------------------
def highlight(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    x = "\033[;103m" + s + "\033[0m"
    return x
# ---------------------------------------------------
def color_text(s, color):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    color = color.lower()
    if color == "red":
        x = "\033[;31m" + s + "\033[0m"
    elif color == "green":
        x = "\033[;32m" + s + "\033[0m"
    elif color == "blue":
        x = "\033[;34m" + s + "\033[0m"
    else:
        x = s
    return x
# ---------------------------------------------------
def color_tag(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    if s[:5:] == "<red>":
        x = "\033[;31m" + s[5:-3:] + "\033[0m"
    elif s[:7:] == "<green>":
        x = "\033[;32m" + s[7:-3:] + "\033[0m"
    elif s[:6:] == "<blue>":
        x = "\033[;34m" + s[6:-3:] + "\033[0m"
    return x
# ---------------------------------------------------
def highlight_words(s, words):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    s = list(s)
    w = list(s)
    c = 0
    for i in range(len(s)):
        for k in range(len(words)):
            if "".join(s[i:i+len(words[k]):]).lower() == words[k].lower():
                w.insert(i+c,"\033[;103m")
                w.insert(i+len(words[k])+1+c,"\033[0m")
                c += 2
    return "".join(w[::])
    # ---------------------------------------------------
def display_tag_file(filename):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    fn = open(filename, 'r', encoding='utf-8')
    line = fn.readline()
    line = list(line)
    w = list(line)
    c = 0
    words = ["<red>","<green>","<blue>"]
    r = []
    while len(line)>0:
        line = list(line)
        w = list(line)
        c = 0
        for i in range(len(line)):
            for k in range(len(words)):
                if "".join(line[i:i+len(words[k]):]) == words[k]:
                    if words[k] == "<red>":
                        x = "\033[;31m"
                    elif words[k] == "<green>":
                        x = "\033[;32m"
                    elif words[k] == "<blue>":
                        x = "\033[;34m"
                    w.insert(i+len(words[k])+c,x)
                    w[i+c:i+len(words[k])+c:] = "$"*len(words[k])
                    c+=1
                if "".join(line[i:i+3]) == "</>":
                    w.insert(i+3+c,"\033[0m")
                    w[i+c:i+3+c:] = "$"*3
                    c+=1
        while "$" in w:
            w.remove("$")
        r.append("".join(w[::]))
        line = fn.readline()
    fn.close()
    print("".join(r))

6530036221: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display0.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 548, 'const': 951, 'code+const': 1499}
def red(s):
    s = "\033[;31m"+s+"\033[0m"
    return s
    pass
# ---------------------------------------------------
def green(s):
    s = "\033[;32m"+s+"\033[0m"
    return s
    pass
# ---------------------------------------------------
def blue(s):
    s = "\033[;34m"+s+"\033[0m"
    return s
    pass
# ---------------------------------------------------
def highlight(s):
    s = "\033[;103m"+s+"\033[0m"
    return s
    pass
# ---------------------------------------------------
def color_text(s, color):
    color = color.lower()
    if color == "red":
        s = "\033[;31m"+s+"\033[0m"
    if color == "green":
        s = "\033[;32m"+s+"\033[0m"
    if color == "blue":
        s = "\033[;34m"+s+"\033[0m"
    return s
    pass
# ---------------------------------------------------
def color_tag(s):
    s = s.split("<")
    A = s[1].split(">")
    color = A[0]
    text = A[1]
    if color == "red":
        text = "\033[;31m"+text+"\033[0m"
    if color == "green":
        text = "\033[;32m"+text+"\033[0m"
    if color == "blue":
        text = "\033[;34m"+text+"\033[0m"
    return text
    pass
# ---------------------------------------------------
def highlight_words(s, words):
    y = list(s)
    a = []
    b = []
    for k in range(len(words)):
        for i in range(len(s)):
            x = s.find(words[k],i)
            if x not in a and x != -1:
                a += [x]
                b += [[x,len(words[k])]]
                b.sort()
    for j in range(len(a)):
        b[j][0] += 2*j
        y.insert(b[j][0],"\033[;103m")
        y.insert(b[j][0]+b[j][1]+1,"\033[0m")
    z = "".join(y)
    return z
    pass
# ---------------------------------------------------
def display_tag_file(filename):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    pass

6530037921: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_10.0
['\x1b[;103mabc\x1b[;0mde\x1b[;103mfg\x1b[;0m\x1b[;103mabc\x1b[;0mabbcbf\x1b[;103mfg\x1b[;0mcd\x1b[;103mabc\x1b[;0maa\x1b[;103mabc\x1b[;0m']
test_highlight_20.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[;0maa\x1b[;103mabc\x1b[;0m']
test_display0.0
abcrrrpkk

defgggocr

xyzbbbabc

abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 1002, 'const': 1180, 'code+const': 2182}
def red(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    word = '\033[;31m'+s+'\033[;0m'
    return word
# ---------------------------------------------------
def green(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    word = '\033[;32m'+s+'\033[;0m'
    return word
# ---------------------------------------------------
def blue(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    word = '\033[;34m'+s+'\033[;0m'
    return word
# ---------------------------------------------------
def highlight(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    word = '\033[;103m'+s+'\033[;0m'
    return word
# ---------------------------------------------------
def color_text(s, color):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    color = color.lower()
    if color == 'red':
        word = '\033[;31m'+s+'\033[;0m'
        return word
    elif color == 'green':
        word = '\033[;32m'+s+'\033[;0m'
        return word
    elif color == 'blue':
        word = '\033[;34m'+s+'\033[;0m'
        return word
    else:
        word = s
    return word
# ---------------------------------------------------
def color_tag(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน:
    x = s.find('>')
    y = s.find('</>')
    cl = s[1:x]
    if cl == 'red':
        word = '\033[;31m'+s[x+1:y]+'\033[;0m'
        return word
    elif cl == 'green':
        word = '\033[;32m'+s[x+1:y]+'\033[;0m'
        return word
    elif cl == 'blue':
        word = '\033[;34m'+s[x+1:y]+'\033[;0m'
        return word
    else:
        word = s[x+1:y]
    return word
# ---------------------------------------------------
def highlight_words(s, words):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    x = s
    for i in words:
        x = x.split(i)
        y = '\033[;103m'+i+'\033[;0m'
        x = y.join(x)
    return x
# ---------------------------------------------------
def display_tag_file(filename):
  # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
  fn = open(filename)
  display = []
  for line in fn:
    display.append(line)
  for i in range(len(display)):
    if "<red>" in display[i]:
      display[i]=display[i].split("<red>")
      for j in range(1,len(display[i])):
        x = display[i][j].find("</>")
        if x != -1:
          display[i][j] =  '\033[;31m'+display[i][j][:x]+'\033[;0m'+display[i][j][x+3:]
      display[i]= "".join(display[i])
    if "<blue>" in display[i]:
      display[i]=display[i].split("<blue>")
      for j in range(1,len(display[i])):
        x = display[i][j].find("</>")
        if x != -1:
          display[i][j] =  '\033[;34m'+display[i][j][:x]+'\033[;0m'+display[i][j][x+3:]
      display[i]= "".join(display[i])
    if "<green>" in display[i]:
      display[i]=display[i].split("<green>")
      for j in range(1,len(display[i])):
        x = display[i][j].find("</>")
        if x != -1:
          display[i][j] =  '\033[;32m'+display[i][j][:x]+'\033[;0m'+display[i][j][x+3:]
      display[i]= "".join(display[i])
  for k in range(len(display)):
    print(display[k])
# ---------------------------------------------------

6530038521: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display0.0
abcrrrpkk

defgggocr

xyzbbbabc

abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 722, 'const': 557, 'code+const': 1279}
def red(s):
    return RED + s + RESET
# ---------------------------------------------------
def green(s):
    return GREEN + s + RESET
# ---------------------------------------------------
def blue(s):
    return BLUE + s + RESET
# ---------------------------------------------------
def highlight(s):
    return HIGHLIGHT + s + RESET
# ---------------------------------------------------
def color_text(s, color):
    if color.lower() == 'red': return red(s)
    elif color.lower() == 'green': return green(s)
    elif color.lower() == 'blue': return blue(s)
    else: return s
# ---------------------------------------------------
def color_tag(s):
    h = ''; i = 0
    while i < len(s):
        if len(s) == 1:
            if s[i] == ' ': break
            else:h += s[i]; break
        elif s[i] == '<':
            c_f = s.find('>',i); re = s.find('</>',c_f)
            if s[i+1].lower() in ['r','g','b']:
                if s[i+1:c_f].lower() == 'red': h += red(s[c_f+1:re])
                elif s[i+1:c_f].lower() == 'green': h += green(s[c_f+1:re])
                elif s[i+1:c_f].lower() == 'blue': h += blue(s[c_f+1:re])
                else: h += s[c_f+1:re]
                i = re + 3
            else:
                if re == -1: h += s[i]; i += 1
                else: h += s[c_f+1:re]; i = re + 3
        else: h += s[i]; i += 1
    return h
# ---------------------------------------------------
def highlight_words(s, words):
    for e in words:
        if e in s: s = s.split(e); s = highlight(e).join(s)
    return s
# ---------------------------------------------------
def display_tag_file(filename):
    fn = open(filename, 'r', encoding='utf-8'); dn = fn.readline()
    while len(dn) > 0:
        print(color_tag(dn)); dn = fn.readline()
    fn.close()

6530039121: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_10.0
['', 'defg', 'abbcbffgcd', 'aa', '']
['de', 'abbcbf', 'cdaa']
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0
['aBCdefgAbcAbbcbffGcd', 'aa', '']
['aBCde', 'AbcAbbcbffGcdaa']
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display0.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 584, 'const': 828, 'code+const': 1412}
def red(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    output='\033[;31m'+s+'\033[0m'
    return output
# ---------------------------------------------------
def green(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    output='\033[;32m'+s+'\033[0m'
    return output
# ---------------------------------------------------
def blue(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    output='\033[;34m'+s+'\033[0m'
    return output
# ---------------------------------------------------
def highlight(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    output='\033[;103m'+s+'\033[0m'
    return output
# ---------------------------------------------------
def color_text(s, color):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    text=''
    color=color.lower()
    if color=='red':
        text=red(s)
    elif color=='green':
        text=green(s)
    elif color=='blue':
        text=blue(s)
    elif color=='highlight':
        text=highlight(s)
    return text
# ---------------------------------------------------
def color_tag(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    idxfir = s.find("<")
    idxlast = s.find(">")
    idxlast2 = s.find("</>")
    color = s[idxfir+1:idxlast]
    text = s[idxlast+1:idxlast2]
    return color_text(text,color)
# ---------------------------------------------------
def highlight_words(s, words):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    save=s
    for w in words:
        ans=""
        lsword=save.split(w)
        print(lsword)
        h=color_text(w,"yellow")
        for i in range(len(lsword)):
            ans += lsword[i]
            if i<len(lsword)-1:
                ans += h
        save=ans
    return save
# ---------------------------------------------------
def display_tag_file(filename):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    file = open(filename,'r',encoding='utf-8')
    fullsentence = ''
    for fi in file :
        idxfir = fi.find('<')
        if idxfir == -1 :
            fullsentence += fi
        while idxfir != -1:
            idxfir = fi.find('<')
            idxlast2 = fi.find('</>')
            change = color_tag(fi[idxfir:idxlast2+3])
            before = fi[0:idxfir]
            after = fi[idxlast2+3::]
            ans = before + change
            fullsentence += ans
            fi = after
    file.close()
    return fullsentence

6530040721: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_21.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display1.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 582, 'const': 454, 'code+const': 1036}
def red(s):
    return RED+str(s)+RESET
# ---------------------------------------------------
def green(s):
    return GREEN+str(s)+RESET
# ---------------------------------------------------
def blue(s):
    return BLUE+str(s)+RESET
# ---------------------------------------------------
def highlight(s):
    return HIGHLIGHT+str(s)+RESET
# ---------------------------------------------------
def color_text(s, color):
    color = color.lower()
    if color == 'red':
        return red(s)
    elif color == 'green':
        return green(s)
    elif color == 'blue':
        return blue(s)
    else:
        return s
# ---------------------------------------------------
def color_tag(s):
    s = s.replace('<red>',RED)
    s = s.replace('<green>',GREEN)
    s = s.replace('<blue>',BLUE)
    s = s.replace('</>',RESET)
    return s
# ---------------------------------------------------
def highlight_words(s, words):
    z0 = s.lower()
    zt = []
    z2 = 0
    op = ''
    for i in words:
        z3 = i.lower()
        while z2 != -1:
            z1=[]
            z2 = z0.find(z3,z2)
            if z2 == -1:
                break
            z1.append(z0.find(z3,z2))
            z1.append(len(i))
            zt.append(z1)
            z2 += len(i)+1
        z2 = 0
    zt.sort()
    for e in zt:
        op+= s[z2:e[0]]
        op+= highlight(s[e[0]:e[0]+e[1]])
        z2 = e[0]+e[1]
    op += s[z2:len(s)]
    return op 
# ---------------------------------------------------
def display_tag_file(filename):
    z = open(filename, 'r', encoding='utf-8')
    z1 = ''
    for i in z:
      i = color_tag(i)
      z1 = z1+str(i)
    z.close()
    print(z1)

6530041321: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_21.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display1.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 930, 'const': 952, 'code+const': 1882}
def red(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return '\033[;31m'+s+'\033[0m'
# ---------------------------------------------------
def green(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return '\033[;32m'+s+'\033[0m'
# ---------------------------------------------------
def blue(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return '\033[;34m'+s+'\033[0m'
# ---------------------------------------------------
def highlight(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return '\033[;103m'+s+'\033[0m'
# ---------------------------------------------------
def color_text(s, color):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    color = color.lower()
    if color == 'red':
        return red(s)
    if color == 'green':
        return green(s)
    if color == 'blue':
        return blue(s)
    else:
        return s
# ---------------------------------------------------
def color_tag(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    n = s.find('>')
    e = s.find('/')
    if s[1:n] == 'red':
        word = s[n+1:e-1]
        return red(word)
    if s[1:n] == 'green':
        word = s[n+1:e-1]
        return green(word)
    if s[1:n] == 'blue':
        word = s[n+1:e-1]
        return blue(word)
# ---------------------------------------------------
def highlight_words(s, words):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    s_new = s.lower()
    for e in words:
        e = e.lower()
        j = s_new.find(e)
        while  j >= 0:
            s = s[0:j]+'\033[;103m'+s[j:j+len(e)]+'\033[0m'+s[j+len(e):len(s)]
            s_new = s_new[0:j]+'\033[;103m'+s_new[j:j+len(e)]+'\033[0m'+s_new[j+len(e):len(s)]
            j += len(e)
            j = s_new.find(e,j+10)
    return s  
# ---------------------------------------------------
def display_tag_file(filename):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    text = ''
    infile = open(filename, 'r', encoding='utf-8')
    for line in infile:
      text += line
    infile.close()
    a = text.find('<')
    b = text.find('>')
    c = text.find('/')
    while  a >= 0:
        if text[a+1:b] == 'red':
            text = text[0:a]+red(text[b+1:c-1])+text[c+2:]
        if text[a+1:b] == 'blue':
            text = text[0:a]+blue(text[b+1:c-1])+text[c+2:]
        if text[a+1:b] == 'green':
            text = text[0:a]+green(text[b+1:c-1])+text[c+2:]
        a = text.find('<',c+2)
        b = text.find('>',c+2)
        c = text.find('/',c+2)
    print(text)

6530042021: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_10.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display1.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 552, 'const': 783, 'code+const': 1335}
def red(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    x = ('\033[;31m'+s+'\033[0m')
    return(x)
# ---------------------------------------------------
def green(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    x = ('\033[;32m'+s+'\033[0m')
    return(x)
# ---------------------------------------------------
def blue(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return('\033[;34m'+s+'\033[0m')
# ---------------------------------------------------
def highlight(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return('\033[;103m'+s+'\033[0m')
# ---------------------------------------------------
def color_text(s, color):
    # ลบบรรทัด pass 
    if color == 'red':
      return(red(s))
    elif color == 'green':
      return(green(s))
    elif color == 'blue':
      return(blue(s))
    else :
      return(s)
# ---------------------------------------------------
def color_tag(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    if '<red>' in s:
      x = s.find('<red>')
      y = s.find('</>')
      z = color_text(s[x+len('<red>'):y],'red')
      return(z)
    elif '<green>' in s:
      x = s.find('<green>')
      y = s.find('</>')
      z = color_text(s[x+len('<green>'):y],'green')
      return(z)
    elif '<blue>' in s:
      x = s.find('<blue>')
      y = s.find('</>')
      z = color_text(s[x+len('<blue>'):y],'blue')
      return(z)
    else :
      return(s)
# ---------------------------------------------------
def highlight_words(s, words):
    # ลบบรรทัด pass 
    for i in words:
      if i in s :
        x = s.replace(i,highlight(i))
      return(x)
# ---------------------------------------------------
def display_tag_file(filename):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    fn = open(filename, 'r', encoding='utf-8')
    line = ''.join(fn.readlines())
    while '</>' in line:
      x = line.find('<')
      y = line.find('</>')
      line = line[:x]+color_tag(line[x:y+3])+line[y+3:]
    print(line)
    fn.close()

6530043621: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_10.0
[Non'\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0
[Non'\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display0.0
abcrrrpkk

defgggocr

xyzbbbabc

abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 898, 'const': 748, 'code+const': 1646}
def red(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    cl = RED + s + RESET
    return(cl)
# ---------------------------------------------------
def green(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    cl = GREEN + s + RESET
    return(cl)
# ---------------------------------------------------
def blue(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    cl = BLUE + s + RESET
    return(cl)
# ---------------------------------------------------
def highlight(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    cl = HIGHLIGHT + s + RESET
    return(cl)
# ---------------------------------------------------
def color_text(s, color):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    color = color.lower()
    if color == "red" :
        cl = RED + s + RESET
    elif color == "green" :
        cl = GREEN + s + RESET
    elif color == "blue" :
        cl = BLUE + s + RESET
    else :
        cl = s
    return(cl)
# ---------------------------------------------------
def color_text2(s,t):
    if s == "red" :
        cl = RED + t + RESET
    elif s == "green" :
        cl = GREEN + t + RESET
    elif s == "blue" :
        cl = BLUE + t + RESET
    else :
        cl = t
    return(cl)
# ---------------------------------------------------
def color_tag(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    wd = ""
    clr = ""
    for i in range(len(s)) :
        if s[i] == ">" :
            clr += s[1:i]
            break
    a = s.find(">")
    b = s.find("<",a)
    wd += s[a+1:b]
    if clr == "red" :
        cl = RED + wd + RESET
    elif clr == "green" :
        cl = GREEN + wd + RESET
    elif clr == "blue" :
        cl = BLUE + wd + RESET
    else :
        cl = wd
    return(cl)
# ---------------------------------------------------
def highlight_words(s, words):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    pass
# ---------------------------------------------------
def colored_text(s):
    txt = []
    clr = ""
    clrs = ""
    for i in range(len(s)) :
        if s[i] == "<" :
            ini = int(i)
        elif s[i] == ">" :
            fin = int(i)
            clr += s[ini+1:fin]
        else :
          pass
    for j in clr :
        if j == "/" :
            clrs += " "
        else:
            clrs += j
    clrs = clrs.strip()
    clrs = clrs.split()
    for k in range(len(s)) :
        if s[k] == ">" :
            initxt = int(k)
        elif s[k] == "<" :
            if s[k+1] in "/" :
                fintxt = int(k)
                txt.append(s[initxt+1:fintxt])
        else :
          pass
    for m in range(len(txt)) :
        s = s.replace('<' + str(clrs[m]) + '>' + str(txt[m]) + '</>',color_text2(str(clrs[m]),str(txt[m])))
    return(s)
# ---------------------------------------------------
def display_tag_file(filename):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    cl = ""
    conv = ""
    file = open(filename, "r", encoding="utf-8")
    for line in file :
        cl = str(colored_text(line))
        conv += cl + "\n"
    file.close()
    return (print(conv))

6530044221: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_21.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display0.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 1708, 'const': 1413, 'code+const': 3121}
def red(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return f'\033[;31m{s}\033[0m'
# ---------------------------------------------------
def green(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return f'\033[;32m{s}\033[0m'
# ---------------------------------------------------
def blue(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return f'\033[;34m{s}\033[0m'
# ---------------------------------------------------
def highlight(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return f'\033[;103m{s}\033[0m'
# ---------------------------------------------------
def color_text(s, color):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    if color.lower() == "red" : return red(s)
    elif color.lower() == "green" : return green(s)
    elif color.lower() == "blue" : return blue(s)
    else : return s
# ---------------------------------------------------
def color_tag(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    z = s ; stop = 0 ; start = 0; clor = "kuy" ; keep_word = False; colorr = ['red', 'blue', 'green']
    text = ""; stop = 0 ; start = 0
    for j in range(0,len(z)):
        if z[start:j] in colorr and z[j] == ">" :
                if z[start:j] == "red" :
                    clor = 31
                elif z[start:j] == "green" :
                    clor = 32
                elif z[start:j] == "blue" :
                    clor = 34
                start = j+1
        elif j == (len(z)-1) and keep_word == True :
            text += f'\033[;{clor}m{z[start:j+1]}\033[0m'
        elif keep_word == False and z[j] == "<" :
                keep_word = True
                stop = j 
                text += z[start:stop]
                start = j+1
        elif keep_word == True and z[j] == "<" :
                keep_word = False
                text += f'\033[;{clor}m{z[start:j]}\033[0m'
        elif z[j] == ">" :
                keep_word == False 
                start = j+1
        elif j == (len(z)-1) and keep_word == False and len(text) == 0 and z[j] != "/" :
            text  += z[start:j+1]
        elif j == (len(z)-1) and keep_word == False :
                text = z
    return text
# ---------------------------------------------------
def highlight_words(s, words):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    words = [words[i].lower() for i in range(0,len(words))]
    i=0
    while i<1000:
        i += 1
        for i in range(0,len(words)):
            for j in range(0,len((words[i]))):
                start= j; 
                if words[i][j].isupper() :
                    start = j+1
                elif words[i][j].islower() :
                    words += [words[i][0:start]+words[i][start:j+1].upper()+words[i][j+1:]]
    newword = []
    for i in range(0,len(words)):
        if words[i] in newword  : 
            pass
        elif words[i].swapcase() in newword :
            pass
        else :
            newword += [words[i],words[i].swapcase()]
    for i in newword :
        s= s.replace(i,f'\033[;103m{i}\033[0m')
    return s
# ---------------------------------------------------
def display_tag_file(filename):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    colorr = ['red', 'blue', 'green']
    z = (open(filename, 'r', encoding='utf-8')).readlines()
    z = [z[i][0:z[i].find("\\")] for i in range(0,len(z))]
    stop = 0 ; start = 0; clor = "kuy" ; keep_word = False
    for i in range(0,len(z)):
        text = ""; stop = 0 ; start = 0
        for j in range(0,len(z[i])):
            if z[i][start:j] in colorr and z[i][j] == ">" :
                if z[i][start:j] == "red" :
                    clor = 31
                elif z[i][start:j] == "green" :
                    clor = 32
                elif z[i][start:j] == "blue" :
                    clor = 34
                start = j+1
            if j == (len(z[i])-1) and keep_word == True :
                text += f'\033[;{clor}m{z[i][start:j+1]}\033[0m'
            elif keep_word == False and z[i][j] == "<" :
                keep_word = True
                stop = j 
                text += z[i][start:stop]
                start = j+1
            elif keep_word == True and z[i][j] == "<" :
                keep_word = False
                text += f'\033[;{clor}m{z[i][start:j]}\033[0m'
            elif z[i][j] == ">" :
                keep_word == False 
                start = j+1
            elif j == (len(z[i])-1) and keep_word == False and len(text) > 0 and z[i][j] != "/" :
                text += z[i][start:j+1]
            elif j == (len(z[i])-1) and keep_word == False and len(text)==0 :
                text = z[i]
        print(text)

6530045921: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_21.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display1.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 1806, 'const': 954, 'code+const': 2760}
def red(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    x = '\033[;31m'+s + '\033[0m'
    return x
# ---------------------------------------------------
def green(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    x = '\033[;32m'+s + '\033[0m'
    return x
# ---------------------------------------------------
def blue(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    x = '\033[;34m'+s + '\033[0m'
    return x
# ---------------------------------------------------
def highlight(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    x = '\033[;103m'+s + '\033[0m'
    return x
# ---------------------------------------------------
def color_text(s, color):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    color = color.lower()
    if color == "red" :
        return red(s)
    elif color == "green":
        return green(s)
    elif color == "blue" :
        return blue(s)
    elif color != "red" and color != "green" and color != "blue"  :
        return s
# ---------------------------------------------------
def color_tag(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    if s[:5] == "<red>" :
        return red(s[5:-3])
    elif s[:6] == "<blue>" :
        return blue(s[6:-3])
    elif s[:7] == "<green>" :
        return green(s[7:-3])
# ---------------------------------------------------
def highlight_words(s, words):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    x = ""
    ln = []
    l = []
    d = -1
    if words == [] :
        return s
    else :
        for j in range (len(words)) :
            w = words[j].lower()
            for i in range (len(s)) :
                d = s.lower().find(w,d+1)
                ln.append([d,len(w)])
                if d == -1 : break
        for i in range (len(ln)) :
            if ln[i][0] != -1 :
                l.append(ln[i])
        l.sort()
        location = []
        lenw = []
        for i in range (len(l)) :
            location.append(l[i][0])
            lenw.append(l[i][1])
        if len(location) < 1 :
            return s
        for i in range (len(location)) :
            if len(location) == 1 :
                x += s[0:location[0]] + highlight(s[location[0]:location[0]+lenw[0]]) + s[location[0]+lenw[0]:]
            elif len(location) > 1 :
                if i == 0 :
                    x += s[0:location[0]] + highlight(s[location[0]:location[0]+lenw[0]])
                elif 0 < i < len(location)-1 :
                    x += s[location[i-1]+lenw[i-1]:location[i]] + highlight(s[location[i]:location[i]+lenw[i]])
                elif i == len(location)-1 :
                    x += s[location[i-1]+lenw[i-1]:location[i]] + highlight(s[location[i]:location[i]+lenw[i]]) + s[location[i]+lenw[i]:]
        return x
# ---------------------------------------------------
def display_tag_file(filename):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
     fn = open(filename, 'r', encoding='utf-8')
     x = ""
     location = []
     r1 = -1
     b1 = -1
     g1 = -1
     pekka = 0 #where is </>
     ans = ""
     start  =[]
     color = []
     end = []
     for line in fn :
         x += line
     fn.close()
     for i in range (len(x)) :
         if x[i:i+5] == "<red>" :
             r1 = x.find("<red>",r1+1)
             l = x.find("</>",pekka+1)
             pekka = l
             location.append([r1,red(x[r1+5:l]),l+3])
         elif x[i:i+6] == "<blue>" :
             b1 = x.find("<blue>",b1+1)
             l = x.find("</>",pekka+1)
             pekka = l
             location.append([b1,blue(x[b1+6:l]),l+3])
         elif x[i:i+7] == "<green>" :
             g1 = x.find("<green>",g1+1)
             l = x.find("</>",pekka+1)
             pekka = l
             location.append([g1,green(x[g1+7:l]),l+3])
     for i in range (len(location)) :
         start.append(location[i][0])
         color.append(location[i][1])
         end.append(location[i][2])
     if len(start) == 0 :
         ans += x
     for i in range (len(start)) :
         if len(start) == 1 :
             ans += x[0:start[0]] + color[0] + x[end[0]:]
         elif len(start) > 0 :
             if i == 0 :
                 ans += x[0:start[0]] + color[0]
             elif 0 < i < len(start)-1 :
                 ans += x[end[i-1]:start[i]] + color[i]
             elif i == len(location)-1 :
                 ans += x[end[i-1]:start[i]] + color[i] + x[end[i]:]
     print (ans)

6530046521: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display1.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 364, 'const': 509, 'code+const': 873}
def red(s):
    colored = RED + s + RESET
    return colored
# ---------------------------------------------------
def green(s):
    colored = GREEN + s + RESET
    return colored
# ---------------------------------------------------
def blue(s):
    colored = BLUE + s + RESET
    return colored
# ---------------------------------------------------
def highlight(s):
    colored = HIGHLIGHT + s + RESET
    return colored
# ---------------------------------------------------
def color_text(s, color):
    colored = ''
    if color.lower() == "red":
        colored = red(s)
    elif color.lower() == "green":
        colored = green(s)
    elif color.lower() == "blue":
        colored = blue(s)
    else:
        colored = s
    return colored
# ---------------------------------------------------
def color_tag(s):
    tagged = s.replace('<red>', '\033[;31m')
    tagged = tagged.replace('<green>', '\033[;32m')
    tagged = tagged.replace('<blue>', '\033[;34m')
    tagged = tagged.replace('</>', '\033[0m')
    return tagged
# ---------------------------------------------------
def highlight_words(s, words):
    for c in words:
        s = s.replace(c, highlight(c))
    return s
# ---------------------------------------------------
def display_tag_file(filename):
    file = open(filename, 'r', encoding='utf-8')
    for line in file:
        c = color_tag(line.strip())
        print(c)
    file.close()

6530047121: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_10.0
abc
abcbffgcdabcaaabcdefgabc
abcbffgcdabcaaabcdefgabcabbcbffgcdabc
abcbffgcdabcaaabcdefgabcabbcbffgcdabcaaabc
['\x1b[;103mabc\x1b[0mbffgcdabcaaabcde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0
aBCdefgAbcAbbcbffGcdabc
aBCdefgAbcAbbcbffGcdabcaaabc
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display0.0FileNotFoundError("No such file or directory: 'มหาจุฬาลงกรณ์-tag.txt'")
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 920, 'const': 743, 'code+const': 1663}
def red(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    x=RED+s+RESET
    return x
# ---------------------------------------------------
def green(s):
   # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    x=GREEN+s+RESET
    return x
# ---------------------------------------------------
def blue(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    x=BLUE+s+RESET
    return x
# ---------------------------------------------------
def highlight(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    x=HIGHLIGHT+s+RESET
    return x
# ---------------------------------------------------
def color_text(s, color):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    if color.lower()=="red":
        return RED+s+RESET
    if color.lower()=="green":
        return GREEN+s+RESET
    if color.lower()=="blue":
        return BLUE+s+RESET
    return s
# ---------------------------------------------------
def color_tag(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    a=s.find("<")
    b=s.find(">")
    c=s.find("<",b+1)
    d=s.find(">",b+1)
    if s[a+1:b:]=="red" and s[c+1:d:]=="/":
        return RED+s[b+1:c:]+RESET
    if s[a+1:b:]=="green" and s[c+1:d:]=="/":
        return GREEN+s[b+1:c:]+RESET
    if s[a+1:b:]=="blue" and s[c+1:d:]=="/":
        return BLUE+s[b+1:c:]+RESET
# ---------------------------------------------------
def highlight_words(s, words):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    a=0
    b=0
    c=""
    for i in words:
        while a>=0:
            a=s.find(str(i),b)
            if a<0:
                #c+=s[len(c):len(s):]
                break
            else:
                c+=s[b:a:]+HIGHLIGHT+s[a:(a+len(i)):]+RESET#+s[(a+len(i)):len(c):]
                b=a+len(i)
                print(c)
            c+=s[len(c):len(s):]
    return c
# ---------------------------------------------------
def display_tag_file(filename):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    f=open('มหาจุฬาลงกรณ์-tag.txt', 'r', encoding='utf-8')
    result=''
    for l in f:
      i=0
      while i<len(l):
        if l[i] == '<':
          j=i+1
          tem=['','']
          while l[j]!='>': 
            tem[0]+=l[j]
            j+=1
          k=j+1
          while l[k]!='<': 
            tem[1]+=l[k]
            k+=1
          i=k+2
          if tem[0]=='red': ts=red(tem[1])
          elif tem[0]=='blue': ts=blue(tem[1])
          elif tem[0]=='green': ts=green(tem[1])
          result+=ts
        else: result+=l[i]
        i+=1
    f.close()
    print(result)
    return

6530048821: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display1.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 712, 'const': 867, 'code+const': 1579}
def red(s):
    s = RED+s+RESET
    return s
# ---------------------------------------------------
def green(s):
    s = GREEN+s+RESET
    return s
# ---------------------------------------------------
def blue(s):
    s = BLUE+s+RESET
    return s
# ---------------------------------------------------
def highlight(s):
    s = HIGHLIGHT+s+RESET
    return s
# ---------------------------------------------------
def color_text(s, color):
    color = color.lower()
    if color == 'red':
      return red(s)
    elif color == 'green':
      return green(s)
    elif color == 'blue':
      return blue(s)
    else: return s
# ---------------------------------------------------
def color_tag(s):
    if s[1] == 'r':
      s = s.replace('<red>',RED)
      s = s.replace('</>',RESET)
      return s
    elif s[1] == 'g':
      s = s.replace('<green>',GREEN)
      s = s.replace('</>',RESET)
      return green(s)
    elif s[1] == 'b':
      s = s.replace('<blue>',BLUE)
      s = s.replace('</>',RESET)
      return blue(s)
# ---------------------------------------------------
def highlight_words(s, words):
    if len(words) == 0:
      return s
    else:
      for i in range(len(words)):
        words[i] = words[i].lower()
      listofs = s.split()
      for i in range(len(listofs)):
        if listofs[i].lower() in words:
          listofs[i] = HIGHLIGHT+listofs[i]+RESET
      result = ''
      for i in listofs:
        result += i+' '
      for i in words:
        result = result.replace(i,HIGHLIGHT+i+RESET)
      return(result.strip())
# ---------------------------------------------------
def display_tag_file(filename):
    f = open(filename, "r", encoding="utf-8")
    s = f.readlines()
    for i in range(len(s)):
      s[i] = s[i].replace('<red>',RED)
      s[i] = s[i].replace('<green>',GREEN)
      s[i] = s[i].replace('<blue>',BLUE)
      s[i] = s[i].replace('</>',RESET)
    result = ''
    for i in s:
      result += i
    print(result)
def test():
    t = 'ไปเรียนAntที่ antโรงเรียนanTที่ ไปแต่aNtไม่เรียนantที่ นั่นแต่ไป'
    print(highlight_words(t,['ant']))

6530049421: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_10.0
['\x1b[;103mabc\x1b[0mde\x1b[;103m\x1b[;103m\x1b[;103mfg\x1b[0m\x1b[0m\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103m\x1b[;103m\x1b[;103m\x1b[;103m\x1b[;103m\x1b[;103mfg\x1b[0m\x1b[0m\x1b[0m\x1b[0m\x1b[0m\x1b[0mcd\x1b[;103m\x1b[;103m\x1b[;103mabc\x1b[0m\x1b[0m\x1b[0maa\x1b[;103m\x1b[;103mabc\x1b[0m\x1b[0m']
test_highlight_20.0
['\x1b[;103maBC\x1b[0mde\x1b[;103m\x1b[;103m\x1b[;103mfg\x1b[0m\x1b[0m\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103m\x1b[;103m\x1b[;103m\x1b[;103m\x1b[;103m\x1b[;103mfG\x1b[0m\x1b[0m\x1b[0m\x1b[0m\x1b[0m\x1b[0mcd\x1b[;103m\x1b[;103m\x1b[;103mabc\x1b[0m\x1b[0m\x1b[0maa\x1b[;103m\x1b[;103mabc\x1b[0m\x1b[0m']
test_display1.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 736, 'const': 469, 'code+const': 1205}
def red(s):
    return RED + str(s) + RESET
# ---------------------------------------------------
def green(s):
    return GREEN + str(s) + RESET
# ---------------------------------------------------
def blue(s):
    return BLUE + str(s) + RESET
# ---------------------------------------------------
def highlight(s):
    return HIGHLIGHT + str(s) + RESET
# ---------------------------------------------------
def color_text(s, color):
    color = color.lower()
    if color == "blue":
        return blue(s)
    if color == "red":
        return red(s)
    if color == "green":
        return green(s)
    return s
# ---------------------------------------------------
def color_tag(s):
    s = s.split('>')
    t = []
    for e in s:
        if '<' in e:
            m,n = e.split('<')
            if m != '/':
                t.append(m)
            if n != '/':
                t.append(n)
        else:
            t.append(e)
    out  =  ' '
    for i in range(len(t)):
        if t[i] in ['red','green','blue']:
            color, txt =  t[i] , t[i+1]
            t[i] = color_text(txt, color)
            t[i+1]  = ""
    out = ''.join(t)
    return out
# ---------------------------------------------------
def highlight_words(s, words):
    for i in range(len(words)):
        words[i] = words[i].lower()
    ls = s.lower()
    for i in range(len(words)):
        j = -1
        k = 0
        while words[i] in ls[k:]:
            j = ls.find(words[i], k)
            ls = ls[:j] + highlight(ls[j:j+len(words[i])]) + ls[j+len(words[i]):]
            s = s[:j] + highlight(s[j:j+len(words[i])]) + s[j+len(words[i]):]
            k += len(HIGHLIGHT) + len(words[i]) + len(RESET)
    return s
# ---------------------------------------------------
def display_tag_file(filename):
    fn = open(filename, 'r', encoding='utf-8')
    t =''
    for line in fn:
        t += line
    fn.close()
    c = color_tag(t)
    print(c)
# ---------------------------------------------------

6530050021: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0
['\x1b[;103mabcBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103maAbc\x1b[0maAbbcbf\x1b[;103mfgG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display1.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 776, 'const': 849, 'code+const': 1625}
def red(s):
    return '\033[;31m'+s+'\033[0m'
# ---------------------------------------------------
def green(s):
    return '\033[;32m'+s+'\033[0m'
# ---------------------------------------------------
def blue(s):
    return '\033[;34m'+s+'\033[0m'
# ---------------------------------------------------
def highlight(s):
    return '\033[;103m'+s+'\033[0m'
# ---------------------------------------------------
def color_text(s, color):
    color = color.lower()
    if color == "red":
        s = red(s)
        return s
    elif color == "green":
        s = green(s)
        return s
    elif color == "blue":
        s = blue(s)
        return s
    else:
        return s
# ---------------------------------------------------
def color_tag(s):
    if "red" in s[0:6]:
        a = s.find(">")
        b = s.find("</>",4)
        c = s[a+1:b:1]
        return red(c)
    elif "green" in s[0:6]:
        a = s.find(">")
        b = s.find("</>")
        c = s[a+1:b:1]
        return green(c)
    elif "blue" in s[0:6]:
        a = s.find(">")
        b = s.find("</>")
        c = s[a+1:b:1]
        return blue(c)
# ---------------------------------------------------
def highlight_words(s, words):
    s = s.lower()
    if len(str(words)) != 2 and words[0].lower() in s :
            for i in range(len(words)):
                a = ""
                l = s
                word = words[i].lower()
                b = l.find(word)
                while len(l) != 0:
                    a += l[0:b]+highlight(l[b:b+len(word)])
                    l = l[b+len(word)::]
                    b = l.find(word)
                    if b == -1:
                        a += l
                        s = a
                        break
            return a
    else:
        return s
# ---------------------------------------------------
def display_tag_file(filename):
    fn = open(filename, 'r', encoding='utf-8')
    a = ""
    for line in fn:
        while len(line) != 0:
            if "<" in line:
                b=line.find("<")
                e=line.find("</>")
                a += line[0:b] + color_tag(line[b:e+3])
                line = line[e+3::]
            else:
                a += line
                line = ""
        else:
            line = fn.readline
    print(a)
    fn.close()

6530051621: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display0.0
abcrrrpkk

defgggocr

xyzbbbabc

abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 454, 'const': 548, 'code+const': 1002}
def red(s):
    return RED + s + RESET
# ---------------------------------------------------
def green(s):
    return GREEN + s + RESET
# ---------------------------------------------------
def blue(s):
    return BLUE + s + RESET
# ---------------------------------------------------
def highlight(s):
    return HIGHLIGHT + s + RESET
# ---------------------------------------------------
def color_text(s, color):
    c = color.lower()
    if c == "red":
        return red(s)
    elif c == "green":
        return green(s)
    elif c == "blue":
        return blue(s)
    else:
        return s
# ---------------------------------------------------
def color_tag(s):
    if s[1] == 'r' and s[-2] == "/":
        return red(s[5:-3])
    if s[1] == 'g' and s[-2] == "/":
        return green(s[7:-3])
    if s[1] == 'b' and s[-2] == "/":
        return blue(s[6:-3])
# ---------------------------------------------------
def highlight_words(s, words):
    for w in words:
        s = s.replace(w,highlight(w))
    return s
# ---------------------------------------------------
def display_tag_file(filename):
    x = open(filename, 'r', encoding='utf-8')
    k = []
    for c in x:
        l=c
        l = l.replace('<red>',RED)
        l = l.replace('</>',RESET)
        l = l.replace('<green>',GREEN)
        l = l.replace('<blue>',BLUE)
        print(l)
    x.close()

6530052221: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display0.0
abcrrrpkk

defgggocr

xyzbbbabc

abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 564, 'const': 1218, 'code+const': 1782}
def red(s):
  t = '\033[;31m'+ s +'\033[0m'
  return t
# ---------------------------------------------------
def green(s):
  t = '\033[;32m'+ s +'\033[0m'
  return t
# ---------------------------------------------------
def blue(s):
  t = '\033[;34m'+ s +'\033[0m'
  return t
# ---------------------------------------------------
def highlight(s):
  t = '\033[;103m'+ s +'\033[0m'
  return t
# ---------------------------------------------------
def color_text(s, color):
  c = color.upper()
  if c == "RED":
    t = '\033[;31m'+ s +'\033[0m'
  else:
    if c == "GREEN":
      t = '\033[;32m'+ s +'\033[0m'
    else:
      if c == "BLUE":
        t = '\033[;34m'+ s +'\033[0m'
      else:
        t = s  
  return t
# ---------------------------------------------------
def color_tag(s):
  t = ""
  for e in s:
    if e == "<" or e == ">" or e == "/":
      t = t + " "
    else:
      t = t + e
  l = t.split()
  for i in range(1,len(l)):
    if l[0] == "red":
      l[i] = '\033[;31m'+ l[i] +'\033[0m'
    else:
      if l[0] == "green":
        l[i] = '\033[;32m'+ l[i] +'\033[0m'
      else:
        if l[0] == "blue":
          l[i] = '\033[;34m'+ l[i] +'\033[0m'
  l.remove(l[0])
  ans = " ".join(l)
  return ans
# ---------------------------------------------------
def highlight_words(s, words):
  for i in range(len(words)):
    s = s.replace(words[i],'\033[;103m'+ words[i] +'\033[0m')
  return s
# ---------------------------------------------------
def display_tag_file(filename):
  fn = open(filename,"r")
  for line in fn:
      line = line.replace('<red>', '\033[;31m')
      line = line.replace('<green>', '\033[;32m')
      line = line.replace('<blue>', '\033[;34m')
      line = line.replace('</>', '\033[0m')
      print(line)
  fn.close()

6530053921: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display1.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 898, 'const': 623, 'code+const': 1521}
def red(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    s = str(s)
    ans = RED + s + RESET
    return ans
# ---------------------------------------------------
def green(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    s = str(s)
    ans = GREEN + s + RESET
    return ans
# ---------------------------------------------------
def blue(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    s = str(s)
    ans = BLUE + s + RESET
    return ans
# ---------------------------------------------------
def highlight(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    s = str(s)
    ans = HIGHLIGHT + s + RESET
    return ans
# ---------------------------------------------------
def color_text(s, color):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    color = color.lower()
    if color == 'red':
        ans = RED + s + RESET
    elif color == 'blue':
        ans = BLUE + s + RESET
    elif color == 'green':
        ans = GREEN + s + RESET
    elif color == 'highlight':
        ans = HIGHLIGHT + s + RESET
    return ans
# ---------------------------------------------------
def color_tag(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    r = '<red>'
    b = '<blue>'
    g = '<green>'
    stop = '</>'
    if r in s:
        txt = s.replace(r,'').replace(stop,'')
        ans = RED + txt + RESET
    elif b in s:
        txt = s.replace(b,'').replace(stop,'')
        ans = BLUE + txt + RESET
    elif g in s:
        txt = s.replace(g,'').replace(stop,'')
        ans = GREEN + txt + RESET
    return ans
# ---------------------------------------------------
def highlight_words(s, words):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    if len(words) == 0:
        return s
    else:
        for i in range(len(words)):
            w = highlight(words[i])
            s = s.replace(words[i],w)
        return s
# ---------------------------------------------------
def display_tag_file(filename):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    infile = open(filename, "r", encoding ='utf-8')
    r = '<red>'
    b = '<blue>'
    g = '<green>'
    stop = '</>'
    for line in infile:
        if r in line:
            line = line.replace(r, ',,,' + r + ',,,')
        if b in line:
            line = line.replace(b, ',,,' + b + ',,,')
        if g in line:
            line = line.replace(g, ',,,' + g + ',,,')
        if stop in line:
            line = line.replace(stop, ',,,' + stop + ',,,')
        L = line.strip().split(',,,')
        for i in range(1,len(L)-1):
            if L[i-1] == r and L[i+1] == stop :
                L[i] = red(L[i])
            if L[i-1] == b and L[i+1] == stop :
                L[i] = blue(L[i])
            if L[i-1] == g and L[i+1] == stop :
                L[i] = green(L[i])
        joint = ''
        l = joint.join(L)
        l = l.replace(r,'').replace(b,'').replace(g,'').replace(stop,'')
        print(l)
    infile.close()

6530054521: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display1.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 988, 'const': 1113, 'code+const': 2101}
def red(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    RED = '\033[;31m'
    for i in range(len(s)):
        RED+=s[i]
    RED+='\033[0m'
    return(RED)
#print('red text:', red('red text'), 'and normal text')
# ---------------------------------------------------
def green(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    GREEN = '\033[;32m'
    for i in range(len(s)):
        GREEN+=s[i]
    GREEN+='\033[0m'
    return(GREEN)
#print('green text:', green('green text'), 'and normal text')
# ---------------------------------------------------
def blue(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    BLUE = '\033[;34m'
    for i in range(len(s)):
        BLUE+=s[i]
    BLUE+='\033[0m'
    return(BLUE)
#print('blue text:', blue('blue text'), 'and normal text')
# ---------------------------------------------------
def highlight(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    HIGHLIGHT = '\033[;103m'
    for i in range(len(s)):
        HIGHLIGHT+=s[i]
    HIGHLIGHT+=RESET
    return(HIGHLIGHT)
#print('highlight text:', highlight('highlight text'), 'and normal text')
# ---------------------------------------------------
def color_text(s, color):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    if color[0]=='r'or color[0]=='R':
        if color[1]=='e'or color[1]=='E':
            if color[2]=='d'or color[2]=='D':
                return(RED+s)
    elif color[0]=='g'or color[0]=='G':
        if color[1]=='r'or color[1]=='R':
            if color[2]=='e'or color[2]=='E':
                if color[3]=='e'or color[3]=='E':
                    if color[4]=='n'or color[4]=='N':
                        return(GREEN+s)
    elif color[0]=='b'or color[0]=='B':
        if color[1]=='l'or color[1]=='L':
            if color[2]=='u'or color[2]=='U':
                if color[3]=='e'or color[3]=='E':
                    return(BLUE+s)
    else:
        return(RESET+s)
#print(color_text('This is yellow text', 'yellow'))
# ---------------------------------------------------
def color_tag(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    for i in range(len(s)):
        if s[i:i+5]=='<red>':
            s=s.replace(s[i:i+5],RED)
        if s[i:i+7]=='<green>':
            s=s.replace(s[i:i+7],GREEN)
        if s[i:i+6]=='<blue>':
            s=s.replace(s[i:i+6],BLUE)
        if s[i:i+3]=='</>':
            s=s.replace(s[i:i+3],RESET)
    return s
#print(color_tag('<blue>blue text</>'))
# ---------------------------------------------------
def highlight_words(s, words):
    RESET = '\033[0m'
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    HIGHLIGHT = '\033[;103m'
    k=[]    
    for i in range(len(words)):
        k.append(words[i].lower())
        k.append(words[i].upper())
    zxc=len(k)
    for i in range(zxc):
        s=s.replace(k[i],highlight(k[i]))
    return s
#t = 'a[3]มิใช่ลิสต์ คืนค่ามิใช่print =มิใช่เปรียบเทียบ รักมิใช่ดวงดาวที่พราวแสง'
#w = ['print', 'ดาว', 'มิใช่']
#z = highlight_words(t, w)
#print(z)
# ---------------------------------------------------
def display_tag_file(filename):
    Answer = ''
    xyz= ''
    xx = open(filename, 'r', encoding='utf-8')
    for line in xx:
        Answer=str(color_tag(line))
        xyz+=Answer
    xx.close()   
    return(print(xyz))
#display_tag_file('มหาจุฬาลงกรณ์-tag.txt')

6530055121: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display0.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 356, 'const': 790, 'code+const': 1146}
def red(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return f"\033[;31m{s}\033[0m"
# ---------------------------------------------------
def green(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return f"\033[;32m{s}\033[0m"
# ---------------------------------------------------
def blue(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return f"\033[;34m{s}\033[0m"
# ---------------------------------------------------
def highlight(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return f"\033[;103m{s}\033[0m"
# ---------------------------------------------------
def color_text(s, color):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    color = color.lower() 
    if color == "red" : return red(s)
    elif color == "green" : return green(s)
    elif color == "blue" : return blue(s)
    else: return s
# ---------------------------------------------------
def color_tag(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    s = s.replace( "<red>", "\033[;31m" )
    s = s.replace( "<green>", "\033[;32m" )
    s = s.replace( "<blue>", "\033[;34m" )
    s = s.replace( "</>", "\033[0m")
    return s
# ---------------------------------------------------
def highlight_words(s, words):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    #s.replace(words,f"\033[;103m{words}\033[0m")
    for i in words:
      s = s.replace(i,highlight(i))
    return s 
# ---------------------------------------------------
def display_tag_file(filename):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    data = open( filename, 'r', encoding='utf-8' ).read().splitlines()
    string = ""
    for i in data: 
      if i != data[-1] : string += i + "\n"
      else : string += i
    return color_tag(string)

6530056821: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_21.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display1.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 636, 'const': 401, 'code+const': 1037}
def red(s):
    return RED+s+RESET
# ---------------------------------------------------
def green(s):
    return GREEN+s+RESET
# ---------------------------------------------------
def blue(s):
    return BLUE+s+RESET
# ---------------------------------------------------
def highlight(s):
    return HIGHLIGHT+s+RESET
# ---------------------------------------------------
def color_text(s,c):
    c = c.lower()
    if c == 'red':
        return red(s)
    elif c == 'green':
        return green(s)
    elif c == 'blue':
        return blue(s)
    else:
        return s
      # ---------------------------------------------------
def color_tag(s):
    return s.replace('<red>',RED).replace('<green>',GREEN).replace('<blue>',BLUE).replace('</>',RESET)
# ---------------------------------------------------
def highlight_words(s, words):
    if words == []:
        return s
    lp = []
    a = ''
    while True:
        lp = []
        for w in words:
            lp.append(s.lower().find(w.lower()))
        if min(lp) != -1:
            if a == '':
                a = s[:min(lp)]+highlight(s[min(lp):min(lp)+len(words[lp.index(min(lp))])])
            else:
                a = a+s[:min(lp)]+highlight(s[min(lp):min(lp)+len(words[lp.index(min(lp))])])
            s = s[min(lp)+len(words[lp.index(min(lp))]):]
        else:
            if lp == [-1]:
                a += s
                break
            words.pop(lp.index(min(lp)))
            lp.pop(lp.index(min(lp)))
    return a
# ---------------------------------------------------
def display_tag_file(fn):
    with open(fn, 'r', encoding = 'utf-8') as f:
        ls = [l.rstrip() for l in f]
        for l in ls:
            print(color_tag(l))
    return

6530057421: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_10.0
['\x1b[;103m\x1b[;103mabc\x1b[0m\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103m\x1b[;103mabc\x1b[0m\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103m\x1b[;103mabc\x1b[0m\x1b[0maa\x1b[;103m\x1b[;103mabc\x1b[0m\x1b[0m']
test_highlight_20.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0mAbcAbbcbffGcd\x1b[;103mAbc\x1b[;103maAbbcbf\x1b[;103mfG\x1b[0maa\x1b[;103mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display1.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 546, 'const': 546, 'code+const': 1092}
def red(s):
    x = RED + s + RESET
    return x
# ---------------------------------------------------
def green(s):
    x = GREEN + s + RESET
    return x
# ---------------------------------------------------
def blue(s):
    x = BLUE + s + RESET
    return x
# ---------------------------------------------------
def highlight(s):
    x = HIGHLIGHT + s + RESET
    return x
# ---------------------------------------------------
def color_text(s, color):
    color = color.lower()
    if color == 'red':
        x = red(s)
    elif color == 'blue':
        x = blue(s)
    elif color == 'green':
        x = green(s)
    else:
        x = s
    return x
# ---------------------------------------------------
def color_tag(s):
    if '<red>' in s:
        x = s.replace('<red>', RED) 
        x = x.replace('</>', RESET)
    elif '<green>' in s:
        x = s.replace('<green>', GREEN) 
        x = x.replace('</>', RESET)
    elif '<blue>' in s:
        x = s.replace('<blue>', BLUE) 
        x = x.replace('</>', RESET)
    return x
# ---------------------------------------------------
def highlight_words(s, words):
    if len(words) == 0:
        x = s
    for i in words:
        if i in s:
             x = s.replace(i,highlight(i))
             break
    for i in words:
        if i in s:
             x = x.replace(i,highlight(i))
    return x
# ---------------------------------------------------
def display_tag_file(filename):
    fin = open(filename, 'r', encoding='utf-8')
    for line in fin:
        if '<red>' in line:
            line = line.replace('<red>', RED) 
        if '<green>' in line:
            line = line.replace('<green>', GREEN) 
        if '<blue>' in line:
            line = line.replace('<blue>', BLUE) 
        if '</>' in line:
            line = line.replace('</>', RESET)
        line = line.replace('\n','')
        print(line)
    fin.close()
    return

6530058021: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_10.0
['\x1b[;103m\x1b[;103mabc\x1b[0m\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103m\x1b[;103mabc\x1b[0m\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103m\x1b[;103mabc\x1b[0m\x1b[0maa\x1b[;103m\x1b[;103mabc\x1b[0m\x1b[0m']
test_highlight_20.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0mAbcAbbcbffGcd\x1b[;103mAbc\x1b[;103maAbbcbf\x1b[;103mfG\x1b[0maa\x1b[;103mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display1.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 674, 'const': 671, 'code+const': 1345}
def red(s):
    return RED + s + RESET
# ---------------------------------------------------
def green(s):
    return GREEN + s + RESET
# ---------------------------------------------------
def blue(s):
    return BLUE + s + RESET
# ---------------------------------------------------
def highlight(s):
    return HIGHLIGHT + s + RESET
# ---------------------------------------------------
def color_text(s, color):
    ww = color.lower()
    if ww == "red":
        return RED + s + RESET 
    elif ww == "green":
        return GREEN + s + RESET
    elif ww == "blue":
        return BLUE + s + RESET
    else:
        return s
# ---------------------------------------------------
def color_tag(s):
    a = s.strip()
    if a[0] == '<' and a[1] in ('R','r') and a[-1] == '>':
        rr = RED + a[5:-3] + RESET
        return str(rr) 
    elif a[0] == '<' and a[1] in ('G','g') and a[-1] == '>':
        gg = GREEN + a[7:-3] + RESET
        return str(gg)
    elif a[0] == '<' and a[1] in ('B','b') and a[-1] == '>':
        bb = BLUE + a[6:-3] + RESET
        return str(bb)
# ---------------------------------------------------
def highlight_words(s, words):
    if len(words) == 0:
        return s
    else:
        q = s.replace(words[0],HIGHLIGHT + words[0] + RESET)
        a = 0
        while a <= len(words)-1:
            c = q.replace(words[a],HIGHLIGHT + words[a] + RESET)
            q = q.replace(q,c)
            a +=1
        return c
# ---------------------------------------------------
def display_tag_file(filename):
    x = open(filename, 'r', encoding='utf-8')
    a = []
    for y in x:
        a.append(y.replace('\n',''))
    for c in a:
        if '<red>' in c:
            c = c.replace('<red>', RED)
        if '<green>' in c:
            c = c.replace('<green>', GREEN)
        if '<blue>' in c:
            c = c.replace('<blue>', BLUE)
        if '</>' in c:
            c = c.replace('</>', RESET)
        print(c)
    x.close()
# ---------------------------------------------------

6530059721: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_21.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display1.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 774, 'const': 661, 'code+const': 1435}
def red(s):
    return RED+s+RESET
# ---------------------------------------------------
def green(s):
    return GREEN+s+RESET
# ---------------------------------------------------
def blue(s):
    return BLUE+s+RESET
# ---------------------------------------------------
def highlight(s):
    return HIGHLIGHT+s+RESET
# ---------------------------------------------------
def color_text(s, color):
    if color.lower()=="red":
        return red(s)
    elif color.lower()=="green":
        return green(s)
    elif color.lower()=="blue":
        return blue(s)
    else:
        return s
    #exec("global t; t="+color.lower()+"(\'"+s+"\')")
    #return t
# ---------------------------------------------------
def color_tag(s):
    R=False
    G=False
    B=False
    t=""
    ans=""
    i=0
    while i < len(s):
        if not (R or B or G):
            if s[i:i+5] == "<red>":
                R = True
                i+=4
            elif s[i:i+6] == "<blue>":
                B = True
                i+=5
            elif s[i:i+7] == "<green>":
                G = True
                i+=6
            else:
                ans += s[i]
        else:
            if s[i:i+3]=="</>":
                if R:
                    ans += red(t)
                elif B:
                    ans += blue(t)
                elif G:
                    ans += green(t)
                R,G,B = False,False,False
                t=""
                i+=2
            else:
                t += s[i]
        i+=1
    return ans
# ---------------------------------------------------
def highlight_words(s, words):
    c=0
    found= False
    ans = ""
    for i in range(len(s)):
        for j in range(len(words)):
            if s[i+c:i+c+len(words[j])].lower() == words[j].lower():
                ans += highlight(s[i+c:i+c+len(words[j])])
                c += len(words[j])-1
                found = True
                break
        if not found:
            ans += s[i+c:i+c+1]
        found = False
    if ans =="":
        ans = s
    return ans
# ---------------------------------------------------
def display_tag_file(filename):
    fn = open(filename,"r",encoding="utf-8")
    t=""
    for line in fn:
        t+=line
    fn.close()
    print(color_tag(t))

6530060221: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display0.0
abcrrr'pkk

defggg'ocr

xyzbbb'abc

abcrrr'pfggg'orr'zbbb'abc
[]
bytecount: {'code': 686, 'const': 1208, 'code+const': 1894}
def red(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    y = '\033[;31m'+ s + '\033[0m'
    return y
# ---------------------------------------------------
def green(s):
    y = '\033[;32m'+ s + '\033[0m'
    return y
# ---------------------------------------------------
def blue(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    y = '\033[;34m'+ s + '\033[0m'
    return y
# ---------------------------------------------------
def highlight(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    y = '\033[;103m'+ s + '\033[0m'
    return y
# ---------------------------------------------------
def color_text(s, color):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    y = color.lower()
    if y == 'red':
        z = '\033[;31m'+ s + '\033[0m'
    elif y == 'green':
        z = '\033[;32m'+ s + '\033[0m'
    elif y == 'blue':
        z = '\033[;34m'+ s + '\033[0m'
    else:
        z = s
    return z
# ---------------------------------------------------
def color_tag(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    d = ''
    count = 0
    c = []
    i = 0
    a = s[0:-3:1]
    while s[i] != '>':
        d += s[i]
        i += 1
    d += '>'
    b = a.replace(d,'')
    if d == '<red>':
        z = '\033[;31m'+ b + '\033[0m'
    elif d == '<green>':
        z = '\033[;32m'+ b + '\033[0m'
    else :
        z = '\033[;34m'+ b + '\033[0m'
    return z
# ---------------------------------------------------
def highlight_words(s, words):
    if len(words) > 0:
        for i in range (len(words)): 
            y = '\033[;103m'+ words[i] + '\033[0m'
            s = s.replace(words[i], y)
        return s
    else:
        return s
# ---------------------------------------------------
def display_tag_file(filename):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
  b = []
  a = open(filename , 'r', encoding='utf-8')
  line = a.readline()
  while len(line) > 0:
          if '</>' in line:
              line = line.replace('</>' , "\033[0m'")
              b.append(line)
              line = a.readline()
          else :
              b.append(line)
              line = a.readline() 
  for i in range (len(b)):
      if '<red>' in (b[i]):
          b[i] = b[i].replace('<red>', '\033[;31m')
      if '<green>' in (b[i]):
          b[i] = b[i].replace('<green>', '\033[;32m')
      if '<blue>' in (b[i]):
          b[i] = b[i].replace('<blue>', '\033[;34m')
  a.close()
  for i in range (len(b)):
    print(b[i])

6530062521: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_21.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display0.0
abcrrrpkk

defgggocr

xyzbbbabc

abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 958, 'const': 583, 'code+const': 1541}
def red(s):
    return RED+s+RESET
# ---------------------------------------------------
def green(s):
    return GREEN+s+RESET
# ---------------------------------------------------
def blue(s):
    return BLUE+s+RESET
# ---------------------------------------------------
def highlight(s):
    return HIGHLIGHT+s+RESET
# ---------------------------------------------------
def color_text(s, color):
    c = color.upper()
    if c == 'RED': return RED+s+RESET
    elif c == 'GREEN': return GREEN+s+RESET
    elif c == 'BLUE': return BLUE+s+RESET
    else : return s
# ---------------------------------------------------
def color_tag(s):
    z = s.find('</>')
    if s.find('red') == 1 :
        x = s[5:z]
        return RED+x+RESET
    if s.find('green') == 1 :
        x = s[7:z]
        return GREEN+x+RESET
    if s.find('blue') == 1 :
        x = s[6:z]
        return BLUE+x+RESET
# ---------------------------------------------------
def highlight_words(s, words):
    L = s.lower()
    for i in range(len(words)):
        o = 0
        p = L.find(words[i].lower(),o)
        while p != -1 :
            x = s[p:p+len(words[i])]
            s = s[:p] + HIGHLIGHT+x+RESET + s[p+len(words[i]):]
            L = s.lower()
            o = p+len(HIGHLIGHT+x+RESET)
            p = L.find(words[i].lower(),o)
    return s
# ---------------------------------------------------
def display_tag_file(filename):
    F = open( filename , 'r', encoding='utf-8')
    for line in F :
        Or = 0
        Pr = line.find('<red>',Or)
        while Pr != -1 :
            Rfr = line.find('</>',Pr)
            Xr = line[Pr+len('<red>'):Rfr]
            line = line[:Pr] + RED+Xr+RESET + line[Rfr+len('</>'):]
            Or = Pr + len(RED+Xr+RESET)
            Pr = line.find('<red>',Or)
        Og = 0
        Pg = line.find('<green>',Og)
        while Pg != -1 :
            Rfg = line.find('</>',Pg)
            Xg = line[Pg+len('<green>'):Rfg]
            line = line[:Pg] + GREEN+Xg+RESET + line[Rfg+len('</>'):]
            Og = Pg + len(GREEN+Xg+RESET)
            Pg = line.find('<green>',Og)
        Ob = 0
        Pb = line.find('<blue>',Ob)
        while Pb != -1 :
            Rfb = line.find('</>',Pb)
            Xb = line[Pb+len('<blue>'):Rfb]
            line = line[:Pb] + BLUE+Xb+RESET + line[Rfb+len('</>'):]
            Ob = Pb + len(BLUE+Xb+RESET)
            Pb = line.find('<blue>',Ob)
        print(line)
    F.close()

6530063121: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_10.0
['\x1b[;103ma\x1b[0m\x1b[;103mb\x1b[0m\x1b[;103mc\x1b[0mde\x1b[;103mf\x1b[0m\x1b[;103mg\x1b[0m\x1b[;103ma\x1b[0m\x1b[;103mb\x1b[0m\x1b[;103mc\x1b[0mabbcbf\x1b[;103mf\x1b[0m\x1b[;103mg\x1b[0mcd\x1b[;103ma\x1b[0m\x1b[;103mb\x1b[0m\x1b[;103mc\x1b[0maa\x1b[;103ma\x1b[0m\x1b[;103mb\x1b[0m\x1b[;103mc\x1b[0m']
test_highlight_20.0
['\x1b[;103ma\x1b[0m\x1b[;103mB\x1b[0m\x1b[;103mC\x1b[0mde\x1b[;103mf\x1b[0m\x1b[;103mg\x1b[0m\x1b[;103mA\x1b[0m\x1b[;103mb\x1b[0m\x1b[;103mc\x1b[0mAbbcbf\x1b[;103mf\x1b[0m\x1b[;103mG\x1b[0mcd\x1b[;103ma\x1b[0m\x1b[;103mb\x1b[0m\x1b[;103mc\x1b[0maa\x1b[;103ma\x1b[0m\x1b[;103mb\x1b[0m\x1b[;103mc\x1b[0m']
test_display1.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 718, 'const': 504, 'code+const': 1222}
def red(s):
    return RED + s + RESET
# ---------------------------------------------------
def green(s):
    return GREEN + s + RESET
# ---------------------------------------------------
def blue(s):
    return BLUE + s + RESET
# ---------------------------------------------------
def highlight(s):
    return HIGHLIGHT + s + RESET
# ---------------------------------------------------
def color_text(s, color):
    if color.upper() == "RED":
      return RED + s + RESET
    elif color.upper() == "BLUE":
      return BLUE + s + RESET
    elif color.upper() == "GREEN":
      return GREEN + s + RESET
    else:
      return s
# ---------------------------------------------------
def color_tag(s):
    y=""
    for i in range (1,len(s)-1):
      y+= s[i]
      if s[i+1]==">":
        break
    p= s.find(">")
    z=""
    for i in range (p+1,len(s)-1):
      z+=s[i]
      if s[i+1]=="<":
        break
    return color_text(z,y)
# ---------------------------------------------------
def highlight_words(s, words):
    u=s.upper()
    ss=""
    list_pos=[]
    count_list=[]
    k=0
    for i in words:
        k=0
        ui = i.upper()
        while True:
          k= u.find(ui,k)
          if k != -1:
            list_pos.extend(range(k,k+len(ui)))
            k+=len(ui)
          elif k==-1:
            break
    sort_list=sorted(list_pos)
    for a in range(len(s)):
      if a in sort_list:
        ss += highlight(s[a])
      else:
        ss += s[a]
    return ss
# ---------------------------------------------------
def display_tag_file(filename):
    o = open(filename, 'r', encoding='utf-8')
    n=0
    line_pos=[]
    line_index=[]
    ans=""
    for line in o:
      n=0
      y=0
      while True:
        n = line.find("<",n)
        slash = line.find("/",n)
        if n != -1:
          ans+= line[y:n]
          ans+= color_tag(line[n:slash+2])
          n=slash
          y=slash+2
        elif n==-1:
          ans+= line [y:]
          break
    o.close()
    print (ans)

6530064821: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_21.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display1.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 800, 'const': 619, 'code+const': 1419}
def red(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return RED + s + RESET
# ---------------------------------------------------
def green(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return GREEN + s + RESET
# ---------------------------------------------------
def blue(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return BLUE + s + RESET
# ---------------------------------------------------
def highlight(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return HIGHLIGHT + s + RESET
# ---------------------------------------------------
def color_text(s, color):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    red = RED + s + RESET
    green = GREEN + s + RESET
    blue = BLUE + s + RESET
    a = color.lower()
    if a == "red":
        return red
    if a == "green":
        return green
    if a == "blue":
        return blue
    else:
        return s
# ---------------------------------------------------
def color_tag(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    for i in range(len(s)):
        a = s.find(">")
        b = s.find("<", 1)
    text = s[a+1:b]
    red = RED + text + RESET
    green = GREEN + text + RESET
    blue = BLUE + text + RESET
    if s[1:a] == "red":
        return red
    if s[1:a] == "green":
        return green
    if s[1:a] == "blue":
        return blue
# ---------------------------------------------------
def highlight_words(s, words):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    if len(words) == 0:
      return s
    for txt in words:
        want = ""
        length = len(txt)
        i = 0
        while i < len(s): 
            if s[i:i+length].lower() == txt.lower():
                want += highlight(s[i:i+length])
                i = i + length
            else:
                want += s[i]
                i += 1
        s = want
    return s
# ---------------------------------------------------
def display_tag_file(filename):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    s = ""
    file = open(filename, 'r', encoding = 'utf-8')
    for line in file:
        s += line
    file.close()
    while "<red>" in s:
        indexStart = s.find("<red>")
        indexStop = s.find("</>",indexStart) + 3
        s = s[0:indexStart] + color_tag(s[indexStart:indexStop]) + s[indexStop:]
    while "<green>" in s:
        indexStart = s.find("<green>")
        indexStop = s.find("</>",indexStart) + 3
        s = s[0:indexStart] + color_tag(s[indexStart:indexStop]) + s[indexStop:]
    while "<blue>" in s:
        indexStart = s.find("<blue>")
        indexStop = s.find("</>",indexStart) + 3
        s = s[0:indexStart] + color_tag(s[indexStart:indexStop]) + s[indexStop:]
    print(s)

6530065421: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display0.0FileNotFoundError("No such file or directory: 'มหาจุฬาลงกรณ์-tag.txt'")
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 1536, 'const': 1883, 'code+const': 3419}
def red(s):   
    return RED+s+RESET
# ---------------------------------------------------
def green(s):   
    return GREEN+s+RESET
# ---------------------------------------------------
def blue(s):
    return BLUE+s+RESET
# ---------------------------------------------------
def highlight(s):   
    return HIGHLIGHT+s+RESET
# ---------------------------------------------------
def color_text(s,color):
    if color.lower() == 'red' :
        return red(s)
    elif color.lower() == 'green' :
        return green(s)
    elif color.lower() == 'blue' :
        return blue(s)
    else :
        return s
# ---------------------------------------------------
def color_tag(s):
    color = ''
    text = ''
    co1 = s.find('<')
    co2 = s.find('>')
    co3 = s.find('<',co2)
    for i in s[co1+1:co2] :
        color += i       
    for i in s[co2+1:co3] :
        text += i
    return (color_text(text,color))
# ---------------------------------------------------
def highlight_words(s, words):
  for i in words :
      s = s.replace(i,highlight(i))
  return s
# ---------------------------------------------------
def display_tag_file(filename):
    fn = open('มหาจุฬาลงกรณ์-tag.txt', 'r', encoding='utf-8')
    s = ''
    for line in fn :
       s += line
    fn.close()
    output = ''
    before = 0
    after  = 0
    seq_key_red = []
    seq_key_blue = []
    seq_key_green = []
    seq_key_all  = [] 
    while True :     
        before = s.find('<red>',0+after)
        after  = s.find('</>',0+before+1)        
        if before == -1 :
             break
        if after == -1 :
             break
        seq_key = before+5       
        seq_key_red.append(seq_key)              
        keyword = s[before+5:after]      
        keyword_color = RED+keyword+RESET
        output += keyword_color + " "
        keyword = ''
        keyword_color = ''
        seq_key = 0       
        ####################################
    while True :
        before = s.find('<blue>',0+after)
        after  = s.find('</>',0+before+1)
        if before == -1 :
            break
        if after == -1 :
            break
        seq_key = before+6   ######## 6 == <blue>       
        seq_key_blue.append(seq_key)      
        keyword = s[before+6:after]
        keyword_color = BLUE+keyword+RESET
        output += keyword_color + " "
        keyword_color = ''
        seq_key = 0       
        ###############################
    while True :
        before = s.find('<green>',0+after)
        after  = s.find('</>',0+before+1)
        if before == -1 :
            break
        if after == -1 :
            break
        seq_key = before+7   ######## 7 == <green>        
        seq_key_green.append(seq_key)      
        keyword = s[before+7:after]
        keyword_color = GREEN+keyword+RESET    
        output += keyword_color + " "
        keyword = ''
        keyword_color = ''
        seq_key = 0    
    cooo = output.split()              
    out = ''
    red,blue,green,cooo =  seq_key_red , seq_key_blue , seq_key_green,cooo
    seq_key_all = (red + blue + green)
    seq_key_all.sort()
    x = seq_key_all
    y = x
    bff = 0
    r = 0
    b = 0
    g  = 0  #### sort แล้ว
    for i in range(len(x)) :
     if x[i] in red :
        out += s[bff:y[i]-5]  + str(cooo[0+r])         ######  -5 เพื่อ ตัด<red> ทิ้ง
        bff = y[i] +len(str(cooo[0+r]))  +3  -10
        r += 1
     elif x[i] in blue :
        out += s[bff:y[i]-6] +str(cooo[len(red)+b]) 
        bff = y[i] +len(str(cooo[len(red)+b])) +3 -10
        b += 1
     elif x[i] in green :
        out += s[bff:y[i]-7] + str(cooo[len(red)+len(blue)+g])
        bff = y[i] +len(str(cooo[len(red)+len(blue)+g]))  + 3 -10
        g += 1    
    out += s[bff:]   
    print(out)
def test() :
    ######### test 1
    print('red text:', red('red text'), 'and normal text')
    print('green text:', green('green text'), 'and normal text')
    print('blue text:', blue('blue text'), 'and normal text')
    print('highlight text:', highlight('highlight text'), 'and normal text')
    ###### test 2
    print(color_text('This is red text', 'red'))
    print(color_text('This is green text', 'GreeN'))
    print(color_text('This is blue text', 'BLUE'))
    print(color_text('This is yellow text', 'yellow'))
    #######  test 3     
    print(color_tag('<red>red text</>'))
    print(color_tag('<green>green text</>'))
    print(color_tag('<blue>blue text</>'))
    ######### test 4    
    t='a[3]มิใช่ลิสต์ คืนค่ามิใช่print =มิใช่เปรียบเทียบ รักมิใช่ดวงดาวที่พราวแสง'    
    print(highlight_words(t,['มิใช่']))
    print(highlight_words(t,['ลิสต์']))      
    print(highlight_words(t, []))      
    w = ['print', 'ดาว', 'มิใช่']
    z = highlight_words(t, w)
    print(z)
    ######### test 5    
    display_tag_file('มหาจุฬาลงกรณ์-tag.txt')

6530066021: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display0.0
abcrrrpkk

defgggocr

xyzbbbabc

abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 460, 'const': 1177, 'code+const': 1637}
def red(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    s = '\033[;31m'+s+'\033[0m'
    return s
# ---------------------------------------------------
def green(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    s = '\033[;32m'+s+'\033[0m'
    return s
# ---------------------------------------------------
def blue(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    s = '\033[;34m'+s+'\033[0m'
    return s
# ---------------------------------------------------
def highlight(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    s = '\033[;103m'+s+'\033[0m'
    return s
# ---------------------------------------------------
def color_text(s, color):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    color = color.lower()
    if (color == 'red'):
        s = '\033[;31m'+s+'\033[0m'
    elif (color == 'green'):
        s = '\033[;32m'+s+'\033[0m'
    elif (color == 'blue'):
        s = '\033[;34m'+s+'\033[0m'
    else :
        return s
    return s
# ---------------------------------------------------
def color_tag(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    if ('<red>' in s ):
        t = s[5:len(s)-3]
        s = '\033[;31m'+t+'\033[0m'
    if ('<green>' in s ):
        t = s[7:len(s)-3]
        s = '\033[;32m'+t+'\033[0m'
    if ('<blue>' in s ):
        t = s[6:len(s)-3]
        s = '\033[;34m'+t+'\033[0m'
    return s
# ---------------------------------------------------
def highlight_words(s, words):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    for i in words:
        h = '\033[;103m'+i+'\033[0m'
        s = s.replace(i,h)
    return s
# ---------------------------------------------------
def display_tag_file(filename):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
     f = open(filename , 'r', encoding='utf-8')
     for l in f:
        l = l.replace('<red>','\033[;31m')
        l = l.replace('<green>','\033[;32m')
        l = l.replace('<blue>','\033[;34m')
        l = l.replace('</>','\033[0m')
        print(l)
     return

6530067721: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display1.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 528, 'const': 505, 'code+const': 1033}
def red(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return RED + s + RESET
# ---------------------------------------------------
def green(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return GREEN + s + RESET
# -nm--------------------------------------------------
def blue(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return BLUE + s + RESET
# ---------------------------------------------------
def highlight(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return HIGHLIGHT + s + RESET
# ---------------------------------------------------
def color_text(s, color):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    if color.upper() == "RED":
        return red(s)
    elif color.upper() == "BLUE":
        return blue(s)
    elif color.upper() == "GREEN":
        return green(s)
    else:
        return s
# ---------------------------------------------------
def color_tag(s):
    s = s = s.replace("<", "datasine").replace(">", "datasine").replace("/", "datasine").split("datasine")
    for i in range(len(s)):
         if s[i] == "red":
             s[i] = ""
             s[i+1] = red(s[i+1])
         elif s[i] == "green":
             s[i] = ""
             s[i+1] = green(s[i+1])
         elif s[i] == "blue":
             s[i] = ""
             s[i+1] = blue(s[i+1])
    t = "".join(s)
    return t
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
# ---------------------------------------------------
def highlight_words(s, words):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    for i in range(len(words)):
        high = words[i]
        gfw = highlight(high)
        s = s.replace(words[i],gfw)
    return s
# ---------------------------------------------------
def display_tag_file(filename):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    gu = ""
    fou = open(filename, 'r', encoding='utf-8')
    for line in fou:
        gu += line
    print(color_tag(gu))  
    fou.close()

6530068321: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display0.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 532, 'const': 1269, 'code+const': 1801}
def red(s):return '\033[;31m'+str(s)+'\033[0m'
# ---------------------------------------------------
def green(s):return '\033[;32m'+str(s)+'\033[0m'
# ---------------------------------------------------
def blue(s):return '\033[;34m'+str(s)+'\033[0m'
# ---------------------------------------------------
def highlight(s):return '\033[;103m'+str(s)+'\033[0m'
# ---------------------------------------------------
def color_text(s, color):
    x=['red','green','blue']
    b=['\033[;31m','\033[;32m','\033[;34m']
    return  b[x.index(color.lower())]+str(s)+'\033[0m'if color.lower() in x else str(s)
# ---------------------------------------------------
def color_tag(s):
    if "<red>"==s[0:5] and "</>"== s[-3:] :return '\033[;31m'+str(s[5:-3])+'\033[0m'
    elif '<blue>' ==s[:6] and "</>"== s[-3:]:return '\033[;34m'+str(s[6:-3])+'\033[0m'
    elif '<green>' ==s[:7] and "</>"== s[-3:]:return '\033[;32m'+str(s[7:-3])+'\033[0m'
# ---------------------------------------------------
def highlight_words(s, words):
    for c in words:s = s.replace(c, '\033[;103m'+str(c)+'\033[0m')
    return s
# ---------------------------------------------------
def display_tag_file(filename):
    a=[] 
    read=open(filename, 'r', encoding='utf-8')
    for line in read:
        line=line.replace("<red>",'\033[;31m')
        line=line.replace("<blue>",'\033[;34m')
        line=line.replace("<green>",'\033[;32m')
        line=line.replace("</>",'\033[;0m')
        a.append(line)
    for s in a :
        print(s , end="")
    read.close()

6530069021: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display0.0
abcrrrpkk

defgggocr

xyzbbbabc

abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 524, 'const': 822, 'code+const': 1346}
def red(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return (RED+s+RESET)
# ---------------------------------------------------
def green(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return (GREEN+s+RESET)
# ---------------------------------------------------
def blue(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return (BLUE+s+RESET)
# ---------------------------------------------------
def highlight(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return (HIGHLIGHT+s+RESET)
# ---------------------------------------------------
def color_text(s, color):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return sol1(s,color)
# ---------------------------------------------------
def color_tag(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return sol2(s)
# ---------------------------------------------------
def highlight_words(s, words):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return sol3(s,words)
# ---------------------------------------------------
def display_tag_file(filename):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    x = []
    read = open(filename, 'r', encoding='utf-8')
    for lines in read:
        lines = lines.replace('<green>','\033[;32m')
        lines = lines.replace('<red>', '\033[;31m')
        lines = lines.replace('<blue>', '\033[;34m')
        lines = lines.replace('</>', '\033[0m')
        x.append(lines)
    for e in x:
        print(e)
# ---------------------------------------------------
def sol1(s,color) :
    if color.lower() == 'red':return red(s)
    elif color.lower() == 'green':return green(s)
    elif color.lower() == 'blue':return blue(s)
    else:return (s)
# ---------------------------------------------------
def sol2(s) :
    if '<red>' in s :
        s=s.replace('<red>','\033[;31m')
        s=s.replace('</>','\033[0m')
    elif '<green>' in s :
        s=s.replace('<green>','\033[;32m')
        s=s.replace('</>','\033[0m')
    elif '<blue>' in s :
        s=s.replace('<blue>','\033[;34m')
        s=s.replace('</>','\033[0m')
    else: pass
    return s
# ---------------------------------------------------
def sol3(t,words) :
    if len(words) == 0:return (t)
    for i in words :
        t = t.replace(i,'\033[;103m'+str(i)+'\033[0m')
    return t
# ---------------------------------------------------

6530070521: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display0.0
abcrrrpkk

defgggocr

xyzbbbabc

abcrrrpfgggo<red>rr</>z<lue>34mbbb</>abc
[]
bytecount: {'code': 1072, 'const': 1009, 'code+const': 2081}
def red(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    texts = '\033[;31m'
    for e in s:
        texts += e
    texts += '\033[0m'
    return texts
# ---------------------------------------------------
def green(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    texts = '\033[;32m'
    for e in s:
        texts += e
    texts += '\033[0m'
    return texts
# ---------------------------------------------------
def blue(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    texts = '\033[;34m'
    for e in s:
        texts += e
    texts += '\033[0m'
    return texts
# ---------------------------------------------------
def highlight(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    texts = '\033[;103m'
    for e in s:
        texts += e
    texts += '\033[0m'
    return texts
# ---------------------------------------------------
def color_text(s, color):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    color = color.lower()
    if color == 'red':
        return red(s)
    if color == 'green':
        return green(s)
    if color == 'blue':
        return blue(s)
    if color != 'red' or color != 'blue' or color != 'green':
        return s
# ---------------------------------------------------
def color_tag(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    s = s.lower()
    first = s.find('>')
    first = int(first)
    last = s.find('<',1)
    last = int(last)
    if s[1] == 'r' and s[2] == 'e' and s[3] == 'd':
        text = ''
        for i in range (first+1, last):
            for e in s[i]:
                text += e
        return red(text)
    if s[1] == 'g' and s[2] == 'r' and s[3] == 'e' and s[4] == 'e' and s[5] == 'n':
        text = ''
        for i in range (first+1, last):
            for e in s[i]:
                text += e
        return green(text)
    if s[1] == 'b' and s[2] == 'l' and s[3] == 'u' and s[4] == 'e':
        text = ''
        for i in range (first+1, last):
            for e in s[i]:
                text += e
        return blue(text)
# ---------------------------------------------------
def highlight_words(s, words):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    alphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
    if len(words) == 0:
        return s
    text = s
    for i in range (len(s)):
        for j in range (1):
            if words[j] in s:
                text = s.replace(words[j],highlight(words[j]))
        for j in range (1,len(words)):
            if words[j] in s:
                text = text.replace(words[j],highlight(words[j]))
    return text
# ---------------------------------------------------
def display_tag_file(filename):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    file = open(filename, "r", encoding="utf-8")
    character = ''
    for ch in file:
        character = ch
        if '<' and '</>' in character:
            start = character.find('<')
            stop = character.find('</>')
            word_color_change = color_tag(character[start:stop+3])
            sentence = character.replace(character[start:stop+3], word_color_change)
        else: return character
        if '<' and '</>' in character[stop+3::]:
            start2 = character.find('<', stop+3)
            stop2 = character.find('</>', stop+3)
            word_color_change = color_tag(character[start2:stop2+3])
            sentence2 = sentence.replace(character[start2:stop2+3], word_color_change)
            print(sentence2)
        else:
            sentence2 = sentence
            print(sentence2)

6530071121: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_10.0
['\x1b[;103m\x1b[;103m\x1b[;103m\x1b[;103mabc\x1b[0m\x1b[0m\x1b[0m\x1b[0mde\x1b[;103m\x1b[;103mfg\x1b[0m\x1b[0m\x1b[;103m\x1b[;103m\x1b[;103m\x1b[;103mabc\x1b[0m\x1b[0m\x1b[0m\x1b[0mabbcbf\x1b[;103m\x1b[;103mfg\x1b[0m\x1b[0mcd\x1b[;103m\x1b[;103m\x1b[;103m\x1b[;103mabc\x1b[0m\x1b[0m\x1b[0m\x1b[0maa\x1b[;103m\x1b[;103m\x1b[;103m\x1b[;103mabc\x1b[0m\x1b[0m\x1b[0m\x1b[0m']
test_highlight_20.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103m\x1b[;103mabc\x1b[0m\x1b[0maa\x1b[;103m\x1b[;103mabc\x1b[0m\x1b[0m']
test_display1.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 1006, 'const': 815, 'code+const': 1821}
def red(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    x = "\033[;31m"
    x += s
    x += "\033[0m"
    return x
# ---------------------------------------------------
def green(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    x = "\033[;32m"
    x += s
    x += "\033[0m"
    return x
# ---------------------------------------------------
def blue(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    x = "\033[;34m"
    x += s
    x += "\033[0m"
    return x
# ---------------------------------------------------
def highlight(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    x = "\033[;103m"
    x += s
    x += "\033[0m"
    return x
# ---------------------------------------------------
def color_text(s, color):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    x = color.upper()
    if x == "RED":
      return red(s)
    elif x == "GREEN":
      return green(s)
    elif x == "BLUE":
      return blue(s)
    else :
      return s
# ---------------------------------------------------
def color_tag(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    if "<red>" in s:
      p1 = s.find("<red>")
      p2 = s.find("</>",p1+1)
      return s[0:p1] + red(s[p1+len("<red>"):p2]) + s[p2+len("</>"):]
    elif "<green>" in s:
      p1 = s.find("<green>")
      p2 = s.find("</>",p1+1)
      return s[0:p1] + green(s[p1+len("<green>"):p2]) + s[p2+len("</>"):]
    elif "<blue>" in s:
      p1 = s.find("<blue>")
      p2 = s.find("</>",p1+1)
      return s[0:p1] + blue(s[p1+len("<blue>"):p2]) + s[p2+len("</>"):]
# ---------------------------------------------------
def highlight_words(s, words):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    t = s[:]
    for i in range(len(words)):
      for j in range(len(s)):
        if s[j:j+len(words[i])].upper() == words[i].upper():         
          t = t.replace(s[j:j+len(words[i])],highlight(s[j:j+len(words[i])]))
    return t
# ---------------------------------------------------
def display_tag_file(filename):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    text = ""
    p1 = 0
    op = open(filename, "r", encoding="utf-8")
    for line in op:
        text += line
    op.close()
    while p1 != -1 :
        if "<red>" in text:
            p1 = text.find("<red>")
            p2 = text.find("</>",p1+1)
            text = text.replace(text[p1:p2+len("</>")],color_tag(text[p1:p2+len("</>")]))
        elif "<blue>" in text:
            p1 = text.find("<blue>")
            p2 = text.find("</>",p1+1)
            text = text.replace(text[p1:p2+len("</>")],color_tag(text[p1:p2+len("</>")]))
        elif "<green>" in text:
            p1 = text.find("<green>")
            p2 = text.find("</>",p1+1)
            text = text.replace(text[p1:p2+len("</>")],color_tag(text[p1:p2+len("</>")]))
        else :
            p1 = -1
    print(text)

6530072821: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_21.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display1.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 628, 'const': 851, 'code+const': 1479}
def red(s):
    RESET = '\033[0m'
    RED = '\033[;31m'
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return RED+s+RESET
# ---------------------------------------------------
def green(s):
    RESET = '\033[0m'
    GREEN = '\033[;32m'
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return GREEN+s+RESET
# ---------------------------------------------------
def blue(s):
    RESET = '\033[0m'
    BLUE = '\033[;34m'
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return BLUE+s+RESET
# ---------------------------------------------------
def highlight(s):
    RESET = '\033[0m'
    HIGHLIGHT = '\033[;103m'
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return HIGHLIGHT+s+RESET
# ---------------------------------------------------
def color_text(s, color):
    color = color.lower()
    if color=="red": return red(s)
    elif color=="green": return green(s)
    elif color=="blue": return blue(s)
    elif color=="highlight": return highlight(s)
    else: return s
# ---------------------------------------------------
def color_tag(s):
    RESET = '\033[0m'
    RED = '\033[;31m'
    GREEN = '\033[;32m'
    BLUE = '\033[;34m'
    return s.replace("<red>", RED).replace("<green>", GREEN).replace("<blue>", BLUE).replace("</>", RESET)
# ---------------------------------------------------
def highlight_words(s, words):
    sLower = s.lower()
    wordsLower = [ch.lower() for ch in words]
    collection = []
    sLength = len(sLower)
    for key in wordsLower:
        i=-1
        length = len(key)
        while i<sLength-1:
            i = sLower.find(key,i+1)
            if i ==-1: break
            collection.append([i,length])
    collection.sort()
    i=0
    highlightWords = ""
    for index,length in collection:
        if i != index:
            highlightWords += s[i:index]
            i=index
        if i == index:
            highlightWords += highlight(s[i:i+length])
            i += length
    if i < sLength:
        highlightWords += s[i:sLength]
    return highlightWords
# ---------------------------------------------------
def display_tag_file(filename):
    file = open(filename, 'r', encoding='utf-8')
    data = ''.join([line for line in file])
    file.close()
    print(color_tag(data))

6530073421: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display1.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 660, 'const': 1101, 'code+const': 1761}
def red(s):
  s = '\033[;31m'+s+'\033[0m'
  return s
# ---------------------------------------------------
def green(s):
  s = '\033[;32m'+s+'\033[0m'
  return s
# ---------------------------------------------------
def blue(s):
  s = '\033[;34m'+s+'\033[0m'
  return s
# ---------------------------------------------------
def highlight(s):
  s = '\033[;103m'+s+'\033[0m'
  return s
#print('red text:', red('red text'), 'and normal text')
#print('green text:', green('green text'), 'and normal text')
#print('blue text:', blue('blue text'), 'and normal text')
#print('highlight text:', highlight('highlight text'), 'and normal text')	
# ---------------------------------------------------
def color_text(s, color):
  color = color.lower()
  if color in ["red","green","blue"]:
    if color == "red":
        s = '\033[;31m'+s+'\033[0m'
        return s
    elif color == "green":
        s = '\033[;32m'+s+'\033[0m'
        return s
    elif color == "blue":
        s = '\033[;34m'+s+'\033[0m'
        return s
  else :
      return s
#print(color_text('This is red text', 'red'))
#print(color_text('This is green text', 'GreeN'))
#print(color_text('This is blue text', 'BLUE'))
#print(color_text('This is yellow text', 'yellow'))	
# ---------------------------------------------------
def color_tag(s):
  if s[1] == "r":
        a = s.find(">")
        b = s.find("<",1)
        s = s[a+1:b]
        s = red(s)
        return s
  elif s[1] == "g":
        a = s.find(">")
        b = s.find("<",1)
        s = s[a+1:b]
        s = green(s)
        return s
  elif s[1] == "b":
        a = s.find(">")
        b = s.find("<",1)
        s = s[a+1:b]
        s = blue(s)
        return s
#print(color_tag('<red>red text</>'))
#print(color_tag('<green>green text</>'))
#print(color_tag('<blue>blue text</>'))	
# ---------------------------------------------------
def highlight_words(s, words):
  for i in words:
    if i in s:
      s = s.replace(i,highlight(i))
  return s
#t = 'a[3]มิใช่ลิสต์ คืนค่ามิใช่print =มิใช่เปรียบเทียบ รักมิใช่ดวงดาวที่พราวแสง'
#print(highlight_words(t,['มิใช่']))
#print(highlight_words(t,['ลิสต์']))
#print(highlight_words(t, []))
#w = ['print', 'ดาว', 'มิใช่']
#z = highlight_words(t, w)
#print(z)
# ---------------------------------------------------
def display_tag_file(filename):
  f = open(filename,"r", encoding='utf-8')
  for line in f:
    line = line.replace("<red>",",<red>")
    line = line.replace("<blue>",",<blue>")
    line = line.replace("<green>",",<green>")
    line = line.replace("</>","</>,")
    inline = line.split(",")
    p = ""
    for i in inline:
        if "<red>" in i:
            p+=color_tag(i)
        elif "<blue>" in i:
            p+=color_tag(i)
        elif "<green>" in i:
            p+=color_tag(i)
        else:
              p+=i
    print(p,end="")

6530074021: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display1.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 980, 'const': 1018, 'code+const': 1998}
def red(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    start=RED
    end=RESET
    a=start[0:11]+s+end[0:8]
    return a
# ---------------------------------------------------
def green(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    start=GREEN
    end=RESET
    a=start[0:11]+s+end[0:8]
    return a
# ---------------------------------------------------
def blue(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    start=BLUE
    end=RESET
    a=start[0:11]+s+end[0:8]
    return a
# ---------------------------------------------------
def highlight(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    start=HIGHLIGHT
    end=RESET
    a=start[0:11]+s+end[0:8]
    return a
# ---------------------------------------------------
def color_text(s, color):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    a=color.lower()
    if a in ['red','green','blue']:
        if a=='red':
            start=RED
            end=RESET
            b=start[0:11]+s+end[0:8]
            return b
        elif a=='green':
            start=GREEN
            end=RESET
            b=start[0:11]+s+end[0:8]
            return b
        elif a=='blue':
            start=RED
            end=RESET
            b=start[0:11]+s+end[0:8]
            return b
    else:
        return s
# ---------------------------------------------------
def color_tag(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    a=s.find('>')
    c=s.find('/')
    if s[a-1] =='d':
        start=RED
        end=RESET
        b=start[0:11]+s[a+1:c-1]+end[0:8]
        return b
    elif s[a-1] =='n':
        start=GREEN
        end=RESET
        b=start[0:11]+s[a+1:c-1]+end[0:8]
        return b
    elif s[a-1] =='e':
        start=BLUE
        end=RESET
        b=start[0:11]+s[a+1:c-1]+end[0:8]
        return b
# ---------------------------------------------------
def highlight_words(s, words):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    if words != []:
        for i in words:
            s=s.replace(i,'\033[;103m'+i+'\033[0m')
    else:
        return s
    return s    
# ---------------------------------------------------
def display_tag_file(filename):
    with open(filename, 'r', encoding='utf-8') as in_file:
        text = ''.join(in_file.readlines())
        list_text = []
        for t in text:
            list_text.append(t)
        color_text = text
        while 'red' in color_text or 'green' in color_text or 'blue' in color_text:
            start = list_text.index('<')
            end = list_text.index('/')
            if list_text[start+1] == 'r':
                list_text[start: start+5] = RED
                list_text[end:end+3] = RESET
            if list_text[start+1] == 'b':
                list_text[start: start+6] = BLUE
                list_text[end-1:end+2] = RESET
            if list_text[start+1] == 'g':
                list_text[start: start+7] = GREEN
                list_text[end-2:end+1] = RESET
            color_text = ''.join(list_text)
        print(color_text)

6530075721: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_10.0
['\x1b[;103m\x1b[;103m\x1b[;103m\x1b[;103mabc\x1b[0m\x1b[0m\x1b[0m\x1b[0mde\x1b[;103m\x1b[;103mfg\x1b[0m\x1b[0m\x1b[;103m\x1b[;103m\x1b[;103m\x1b[;103mabc\x1b[0m\x1b[0m\x1b[0m\x1b[0mabbcbf\x1b[;103m\x1b[;103mfg\x1b[0m\x1b[0mcd\x1b[;103m\x1b[;103m\x1b[;103m\x1b[;103mabc\x1b[0m\x1b[0m\x1b[0m\x1b[0maa\x1b[;103m\x1b[;103m\x1b[;103m\x1b[;103mabc\x1b[0m\x1b[0m\x1b[0m\x1b[0m']
test_highlight_20.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103m\x1b[;103mabc\x1b[0m\x1b[0maa\x1b[;103m\x1b[;103mabc\x1b[0m\x1b[0m']
test_display1.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 1074, 'const': 2650, 'code+const': 3724}
def red(w) :
    return '\033[;31m' + w + '\033[0m'
def green(w) :
    return '\033[;32m' + w + '\033[0m'
def blue(w) :
    return '\033[;34m' + w + '\033[0m'
def highlight(w) :
    return '\033[;103m' + w + '\033[0m'
def color_text(s,color) :
    cl = ['RED','GREEN','BLUE',31,32,34]
    if color.upper() not in cl :
        return s
    x = cl[cl.index(color.upper())+3]
    return '\033[;' + str(x) + 'm' + s + '\033[0m'
def color_tag(s) :
    k = s.find('>')
    color = s[1:k].upper()
    cl = ['RED','GREEN','BLUE',31,32,34]
    if color not in cl :
        return s
    x = cl[cl.index(color)+3]
    return '\033[;' + str(x) + 'm' + s[k+1:-3] + '\033[0m'
def highlight_words(s,word) :
    #bonus : สามารถhighlightได้โดยไม่สนว่าเป็นตัวพิมพ์เล็กหรือตัวพิมพ์ใหญ่ 
    for i in word :
        i,x,w = i.lower(),0,[]
        for j in range(s.lower().count(i)) :
            k = s.lower().find(i,x)
            x = k + len(i)
            w.append(s[k:k+len(i)])
        for j in w :
            s = s.replace(j,'\033[;103m' + j + '\033[0m')
    return s
def display_tag_file(filename) :
    #bonus : สามารถแสดงสีให้ถูกต้องได้เมื่อtagสีและtag</>อยู่คนละบรรทัดกัน checked
    file = open(filename,'r',encoding='utf-8')
    ans = []
    for line in file :
        while '<' in line : 
            a = line.find('<')
            b = line.find('>',a+7)
            if a > -1 and b > -1 : #มีทั้งเปิดปิด
                w = line[a:b+1]
            elif a > -1 and b == -1 and '/' not in line : #มีแต่เปิด
                line = line[:-1] + '</>\n'
                w = line[a:-1] + '</>\n'
                last = line[a:line.find('>')+1]
            else : #มีแต่ปิด
                line = last + line
                w = last + line[:a+3]
            line = line.replace(w,color_tag(w))
        if line[-1] == '\n' :
            ans.append(line[:-1])
        else :
            ans.append(line)
    for i in ans :
        print(i)
    file.close()
def test() :
    #test1
    print('red text :', red('red text'), 'and normal text')
    print('green text :', green('green text'), 'and normal text')
    print('blue text :', blue('blue text'), 'and normal text')
    print('highlight text :', highlight('highlight text'), 'and normal text')
    #test2
    print(color_text('This is red text', 'red'))
    print(color_text('This is green text', 'GreeN'))
    print(color_text('This is blue text', 'BLUE'))
    print(color_text('This is yellow text', 'yellow'))
    #test3
    print(color_tag('<red>red text</>'))
    print(color_tag('<green>green text</>'))
    print(color_tag('<blue>blue text</>'))
    #test4
    t = 'a[3]มิใช่ลิสต์ คืนค่ามิใช่print =มิใช่เปรียบเทียบ รักมิใช่ดวงดาวที่พราวแสง'
    print(highlight_words(t,['มิใช่']))
    print(highlight_words(t,['ลิสต์']))
    print(highlight_words(t, []))
    w = ['print', 'ดาว', 'มิใช่']
    z = highlight_words(t, w)
    print(z)
    t = 'Yourself is one of your own yOursElF not yourselves but YOURself and YouRseLF'
    word = ['yourself']
    print(highlight_words(t,word))
    t = 'sunNy is SUNny not suNNy but SuNNy&suNNY(sUNNy)'
    word = ['SUnny','NoT']
    print(highlight_words(t,word))
    #test5
    display_tag_file('มหาจุฬาลงกรณ์-tag.txt')
    display_tag_file('data.txt')

6530076321: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display1.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 612, 'const': 584, 'code+const': 1196}
def red(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    s = RED + s + RESET
    return s
# ---------------------------------------------------
def green(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    s = GREEN + s + RESET
    return s
# ---------------------------------------------------
def blue(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    s = BLUE + s + RESET
    return s
# ---------------------------------------------------
def highlight(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    s = HIGHLIGHT + s + RESET
    return s
# ---------------------------------------------------
def color_text(s, color):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    color = color.lower()
    if color == 'red':
        s = RED + s + RESET
        return s
    elif color == 'green':
        s = GREEN + s + RESET
        return s
    elif color == 'BLUE':
        s = BLUE + s + RESET
        return s
    else:
        return s
# ---------------------------------------------------
def color_tag(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    text_index1 = s.find(">")
    text_index2 = s.find("<",1)
    a = s[text_index1+1:text_index2]
    if "<red>" in s:
        a =red(a)
    elif "<green>" in s:
        a = green(a)
    elif "<blue>" in s:
        a = blue(a)
    return a
# ---------------------------------------------------
def highlight_words(s, words):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    for i in words:
        if i in s:
            s = s.replace(i,highlight(i))
    return s
# ---------------------------------------------------
def display_tag_file(filename):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    file = open(filename,'r',encoding='utf-8')
    answer = ""
    for line in file:
        linelist = line.split("</>")
        for word in linelist:
            if "<red>" in word:
                t = word.find("<red>")
                answer = answer + word[0:t] + color_tag(word[t:]+"<")
            elif "<green>" in word:
                t = word.find("<green>")
                answer = answer + word[0:t] + color_tag(word[t:]+"<")
            elif "<blue>" in word:
                t  = word.find("<blue>")
                answer = answer + word[0:t] + color_tag(word[t:]+"<")
            else:
                answer = answer + word
    file.close()
    print(answer)

6530077021: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display1.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 442, 'const': 480, 'code+const': 922}
def red(s):
    return RED + s  +RESET
# ---------------------------------------------------
def green(s):
    return GREEN + s  +RESET
# ---------------------------------------------------
def blue(s):
    return BLUE + s  +RESET
# ---------------------------------------------------
def highlight(s):
    return HIGHLIGHT + s  +RESET
# ---------------------------------------------------
def color_text(s, color):
    if color.lower() == 'red': return red(s)
    elif color.lower() == 'green': return green(s)
    elif color.lower() == 'blue': return blue(s)
    else : return s
# ---------------------------------------------------
def color_tag(s):
    color = s[s.find('<')+1:s.find('>')]
    text = s[s.find('>')+1:s.find('</>')]
    return color_text(text,color)
# ---------------------------------------------------
def highlight_words(s, words):
    a = s
    for i in words:    a = a.replace(i,highlight(i))
    return a
# ---------------------------------------------------
def display_tag_file(filename):
    text = ''.join(open(filename, 'r', encoding='utf-8').readlines())
    c = 0
    while c < len(text):
        if text.find('>',c) != -1:
            a = text[text.find('<',c):text.find('</>',c)+3]
            b = color_tag(a)
            text = text.replace(a,b)
            c = text.find('</>',c)+3
        else:
            break
    return print(text)

6530078621: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_10.0AttributeError("'list' object has no attribute 'lower'")
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0AttributeError("'list' object has no attribute 'lower'")
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display1.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 866, 'const': 495, 'code+const': 1361}
def red(s): return RED+s+RESET
# ---------------------------------------------------
def green(s): return GREEN+str(s)+RESET
# ---------------------------------------------------
def blue(s): return BLUE+str(s)+RESET
# ---------------------------------------------------
def highlight(s): return HIGHLIGHT+str(s)+RESET
# ---------------------------------------------------
def color_text(s, color):
    c=color.lower()
    if c=='red': return red(s)
    elif c=='blue': return blue(s)
    elif c=='green': return green(s)
    else: return s
# ---------------------------------------------------
def color_tag(s):
    r=s.find('<red>')
    while r!=-1:
        S=s.find('</>',r+5)
        if S==-1:
            s=s[:r]+s[r+5:]
            break
        s=s[:r]+red(s[r+5:S])+s[S+3:]
        r=s.find('<red>',S+3)
    b=s.find('<blue>')
    while b!=-1:
        S=s.find('</>',b+6)
        if S==-1:
            s=s[:b]+s[b+6:]
            break
        s=s[:b]+blue(s[b+6:S])+s[S+3:]
        b=s.find('<blue>',S+3)
    g=s.find('<green>')
    while g!=-1:
        S=s.find('</>',g+7)
        if S==-1:
            s=s[:g]+s[g+7:]
            break
        s=s[:g]+green(s[g+7:S])+s[S+3:]
        g=s.find('<green>',S+3)
    return s
# ---------------------------------------------------
def highlight_words(s, words):
    d=''
    i=0
    c=s.lower()
    p=words.lower()
    while -1<i<len(c):
        k=c.find(p,i)
        if k==-1:
            d+=s[i:]
            break
        d+=s[i:k]+highlight(s[k:k+len(words)])
        i=k+len(words)
    return d
# ---------------------------------------------------
def display_tag_file(filename):
    O=open(filename, 'r', encoding='utf-8')
    READ=O.readline()
    while len(READ)!=0:
        print (color_tag(READ).strip())
        READ=O.readline()
    O.close()

6530079221: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_10.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103m\x1b[;103mabc\x1b[0m\x1b[0mabbcbf\x1b[;103m\x1b[;103mfg\x1b[0m\x1b[0mcd\x1b[;103m\x1b[;103m\x1b[;103mabc\x1b[0m\x1b[0m\x1b[0maa\x1b[;103m\x1b[;103m\x1b[;103m\x1b[;103mabc\x1b[0m\x1b[0m\x1b[0m\x1b[0m']
test_highlight_20.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103m\x1b[;103mabc\x1b[0m\x1b[0m']
test_display1.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 680, 'const': 1056, 'code+const': 1736}
def red(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return '\033[;31m'+s+'\033[0m'
# print('red text:',red('red text'),'and normal text')
# ---------------------------------------------------
def green(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return '\033[;32m'+s+'\033[0m'
# print('green text:',green('green text'),'and normal text')
# ---------------------------------------------------
def blue(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return '\033[;34m'+s+'\033[0m'
# ---------------------------------------------------
def highlight(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return '\033[;103m'+s+'\033[0m'
# ---------------------------------------------------
def color_text(s, color):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    color=color.lower()
    if color=='red':
        return red(s)
    if color=='green':
        return green(s)
    if color=='blue':
        return blue(s)
    return s
# ---------------------------------------------------
def color_tag(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    g1=s.find('<')
    g2=s.find('>')
    g3=s.find('</>',g2+1)
    if s[g1+1:g2]=='red':
        return red(s[g2+1:g3])
    if s[g1+1:g2]=='green':
        return green(s[g2+1:g3])
    if s[g1+1:g2]=='blue':
        return blue(s[g2+1:g3])
# print(color_tag('<red>red text</>'))
#---------------------------------------------------
def highlight_words(s, words):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    if len(words)==0:
        return s
    else:
        for i in range(len(words)):
            j=0
            while j < len(s):
                k=s.lower().find(words[i].lower(),j)
                if k !=-1:
                    s=s[:k]+s[k:].replace(s[k:k+len(words[i])],'\033[;103m'+s[k:k+len(words[i])]+'\033[0m')
                    j=k+len('\033[;103m'+s[j:][k:k+len(words[i])]+'\033[0m')
                else:
                    j=j+1
                    break
        return s
#t='HappybirthdaytoyouYouyoU'
#print(highlight_words(t,['happy','You','tO']))            
# ---------------------------------------------------
def display_tag_file(filename):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    file=open(filename, 'r', encoding='utf-8')
    for line in file:
        line=line.replace("</>",'\033[0m')
        line=line.replace('<green>','\033[;32m')
        line=line.replace('<red>','\033[;31m')
        line=line.replace('<blue>','\033[;34m')
        print(line,end='')
    file.close()

6530080821: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_21.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display0.0FileNotFoundError("No such file or directory: 'มหาจุฬาลงกรณ์-tag.txt.lyrics'")
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 796, 'const': 995, 'code+const': 1791}
def red(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return '\033[;31m'+s+'\033[0m'
# ---------------------------------------------------
def green(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return '\033[;32m'+s+'\033[0m'
    # ---------------------------------------------------
def blue(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return '\033[;34m'+s+'\033[0m'
# ---------------------------------------------------
def highlight(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return '\033[;103m'+s+'\033[0m'
# ---------------------------------------------------
def color_text(s, color):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    color = color.lower()
    if(color=='red'):
      return red(s)
    if(color=='green'):
      return green(s)
    if(color=='blue'):
      return blue(s)
    return s
# ---------------------------------------------------
def color_tag(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    x = s.find('<',2)
    if(s[1]=='r'):
      return red(s[5:x])
    if(s[1]=='b'):
      return blue(s[6:x])
    if(s[1]=='g'):
      return green(s[7:x])
# ---------------------------------------------------
def highlight_words(s, words):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    para=''
    for e in s:
      para+=e
    para = para.lower()
    mark = []
    for e in words:
      e = e.lower()
      x=-1
      i=0
      while(i!=-1):
        i = para.find(e,x+1)
        x = i
        if(i!=-1):
          mark.append([i,i+len(e)])
    mark.sort()
    ans = ''
    last=0
    for e in mark:
      ans+=s[last:e[0]]
      ans+='\033[;103m'+s[e[0]:e[1]]+'\033[0m'
      last=e[1]
    ans+=s[last:len(s)]
    return ans
# ---------------------------------------------------
def display_tag_file(filename):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    f = open('มหาจุฬาลงกรณ์-tag.txt.lyrics', 'r', encoding='utf-8')
    a=''
    idx=[]
    while(True):
      tmp = f.readline()
      if tmp=="":
        break
      idx.append(len(tmp))
      a+=tmp
    mark = []
    x=-1
    i=0
    while(i!=-1):
      i = a.find('<',x+1)
      k = a.find('>',x+1)
      j = a.find('>',k+1)
      x = j
      if(i!=-1):
        mark.append([i,j+1])
    ans = ''
    last=0
    for e in mark:
      ans+=a[last:e[0]]
      #print(a[e[0]:e[1]])
      ans+=color_tag(a[e[0]:e[1]])
      last=e[1]
    ans+=a[last:len(a)]
    print(ans)
#display_tag_file('ddd')
#t = 'a[3]มิใช่ลิสต์ คืนค่ามิใช่print =มิใช่เปรียบเทียบ รักมิใช่ดวงดาวที่พราวแสง'
#key = ['print', 'ดาว', 'มิใช่']
#print(highlight_words(t,key))
#a = 'Hello hello heLLo'
#print(highlight_words(a,['hello']))

6530081421: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_10.0
[Non'\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0
[Non'\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display1.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 596, 'const': 781, 'code+const': 1377}
def red(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return '\033' + "[;31m" + s+ "\033" + "[0m"
# ---------------------------------------------------
def green(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return '\033' + "[;32m" + s+ "\033" + "[0m"
# ---------------------------------------------------
def blue(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return '\033' + "[;34m" + s+ "\033" + "[0m"
# ---------------------------------------------------
def highlight(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return str('\033' + "[;103m" + s+ "\033" + "[0m")
# ---------------------------------------------------
def color_text(s, color):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    if color.lower() == "red":
        return red(s)
    elif color.lower() == "green":
        return green(s)
    elif color.lower() == "blue":
        return blue(s)
    else :
        return s
# ---------------------------------------------------
def color_tag(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    i = 0
    x = ""
    while i<len(s):
        if s[i] == "<":
            color = ""
            text = ""
            i+=1
            while i<s.find(">",i-1):
                color+= s[i]
                i+=1
            i+=1
            while i<s.find("</>",i-1):
                text += s[i]
                i+=1
            i+=3
            x+=color_text(text,color)
        else :
            x+=s[i]
            i+=1 
    return x
# ---------------------------------------------------
def highlight_words(s, words):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    a = -1
    for i in words :
        b = 0
        while True:
            a = s.lower().find(i.lower(),a+1)
            if a == -1 :
                break
            s = s[b:a] + highlight(s[a:a+len(i)]) + s[a+len(i):]
            if a != -1 : a+=10+len(i)
# ---------------------------------------------------
def display_tag_file(filename):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    file = open(filename, 'r', encoding='utf-8')
    for i in file :
        print(color_tag(i.strip()))

6530082021: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_21.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display1.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 744, 'const': 450, 'code+const': 1194}
def red(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    word = RED + s + RESET
    return word
# ---------------------------------------------------
def green(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    word = GREEN + s + RESET
    return word
# ---------------------------------------------------
def blue(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    word = BLUE + s + RESET
    return word
# ---------------------------------------------------
def highlight(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    word = HIGHLIGHT + s + RESET
    return word
# ---------------------------------------------------
def color_text(s, color):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    check = ['red','green','blue']
    color = color.lower()
    if color in check:
        if color == 'red':
            sen = red(s)
        elif color == 'green':
            sen = green(s)
        elif color == 'blue':
            sen = blue(s)
    else:
        sen = s
    return sen
# ---------------------------------------------------
def color_tag(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    x = s.find('>')
    y = s.find('<',x)
    clr = s[1:x]
    s = s[x+1:y]
    s = color_text(s, clr)
    return s
# ---------------------------------------------------
def highlight_words(s, words):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    for i in range(len(words)):
        x = 0
        j = s.lower()
        k = words[i].lower()
        while x != -1:
            x = j.find(k,x)
            if x == -1:
                pass
            else:
                y = s[x:x+len(words[i])]
                y = highlight(y)
                s = s[:x] + y + s[x+len(words[i]):]
                j = j[:x] + y + j[x+len(words[i]):]
                x += len(y)
    return s
# ---------------------------------------------------
def display_tag_file(filename):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    sen = ''
    fn = open(filename, 'r', encoding='utf-8')
    line = fn.readline()
    while len(line) > 0:
        x = 0
        while x != -1:
            x = line.find('<')
            if x == -1:
                pass
            else:
                y = line.find('>')
                y = line.find('>',y+1)
                if y == -1:
                    new = fn.readline()
                    line += new
                    y = line.find('>')
                    y = line.find('>',y+1)
                z = color_tag(line[x:y+1])
                line = line[:x] + z + line[y+1:]
        sen += line
        line = fn.readline()
    fn.close()
    print(sen)
# ---------------------------------------------------

6530083721: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display1.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 330, 'const': 411, 'code+const': 741}
def red(s):
    return RED + s + RESET
# ---------------------------------------------------
def green(s):
    return GREEN + s + RESET
# ---------------------------------------------------
def blue(s):
    return BLUE + s + RESET
# ---------------------------------------------------
def highlight(s):
    return HIGHLIGHT + s + RESET
# ---------------------------------------------------
def color_text(s, color):
    k = color.upper()
    if k == 'RED':
      return RED + s + RESET
    elif k == 'GREEN':
      return GREEN + s + RESET
    elif k == 'BLUE':
      return BLUE + s + RESET
    else:
      return s
# ---------------------------------------------------
def color_tag(s):
    x = s.replace('</>',RESET)
    x = x.replace('<red>',RED)
    x = x.replace('<blue>',BLUE)
    x = x.replace('<green>',GREEN)
    return x
# ---------------------------------------------------
def highlight_words(s, words):
    a = s
    for i in words:
        a = a.replace(i,highlight(i))
    return a
# ---------------------------------------------------
def display_tag_file(filename):
    f = open(filename, 'r', encoding='utf-8')
    for line in f:
      print(color_tag(line),end = '')

6530084321: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_10.0IndexError('string index out of range')
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0IndexError('string index out of range')
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display1.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 996, 'const': 919, 'code+const': 1915}
def red(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    k = ""
    r1 = RED
    r2 = RESET
    k += r1
    k += s
    k += r2
    return k
# ---------------------------------------------------
def green(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    k = ""
    r1 = GREEN
    r2 = RESET
    k += r1
    k += s
    k += r2
    return k
# ---------------------------------------------------
def blue(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    k = ""
    r1 = BLUE
    r2 = RESET
    k += r1
    k += s
    k += r2
    return k
# ---------------------------------------------------
def highlight(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    k = ""
    a = HIGHLIGHT
    b = RESET
    k += a
    k += s
    k += b
    return k
# ---------------------------------------------------
def color_text(s,color):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    if color.lower() == "red" :
        return red(s)
    elif color.lower() == "green" :
        return green(s)
    elif color.lower() == "blue" :
        return blue(s)
    else :
        return s
# ---------------------------------------------------
def color_tag(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    a = ""
    a += s[s.find("<")+1:s.find(">")]
    b = ""
    b += s[s.find(">")+1:s.find("/")-1]
    if a.lower() == "red" :
        return red(b)
    elif a.lower() == "green" :
        return green(b)
    elif a.lower() == "blue" :
        return blue(b)
    else :
        return b
# ---------------------------------------------------
def highlight_words(s, words):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    a = ""
    i = 0
    while True :
        for e in words :
            if s[i:i+len(e)] == e :
                a += highlight(e)
                i += len(e)
        else :
            a += s[i]
            i +=1
        if i == len(s) -1 : break
    return a
# ---------------------------------------------------
def display_tag_file(filename):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    a = open(filename, 'r', encoding='utf-8')
    r = ""
    for line in a :
        r += line
        r += "***"
    a.close()
    r = r.split("***")
    k = ""
    for i in range(len(r)) :
        for e in r[i] :
            if e == "<" :
                k += "  "
            elif e == ">" :
                k += "  "
            elif e == "/" :
                k += "  "
            else :
                k += e
        k += "***"
    k = k.split("***")
    for i in range(len(k)) :
        k[i] = k[i].split()
    x = ""
    for e in k :
        i = 0
        while i != len(e) :
            if e[i] == "red" :
                x += red(e[i+1])
                i += 2
            elif e[i] == "green" :
                x += green(e[i+1])
                i += 2
            elif e[i] == "blue" :
                x += blue(e[i+1])
                i += 2
            else :
                x += e[i]
                i += 1
        x += "\n"
    print(x)

6530085021: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_10.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m\x1b[;103m\x1b[0m']
test_highlight_20.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m\x1b[;103m\x1b[0m']
test_display1.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 932, 'const': 673, 'code+const': 1605}
def red(s):
    return (RED+s+RESET)
def green(s):
    return (GREEN+s+RESET)
def blue(s):
    return (BLUE+s+RESET)
def highlight(s):
    return (HIGHLIGHT+s+RESET)
def color_text(s, color):
    if color.lower() == "red":
        cl = RED
    elif color.lower() == "green":
        cl = GREEN
    elif color.lower() == "blue":
        cl = BLUE
    else:
        cl = ""
    return (cl+s+RESET)
def color_tag(s):
    if "<red>" in s:
        x = s.find("<red>")+5
        y = s.find("</>")
        return s[:x-5]+red(s[x:y])+s[y+3:]
    elif "<green>" in s:
        x = s.find("<green>")+7
        y = s.find("</>")
        return s[:x-7]+green(s[x:y])+s[y+3:]
    elif "<blue>" in s:
        x = s.find("<blue>")+6
        y = s.find("</>")
        return s[:x-6]+blue(s[x:y])+s[y+3:]
    else:
        return s
def highlight_words(s, words):
    k = 0
    lst = []
    e = s.lower()
    for i in words:
        i = i.lower()
        while e.find(i,k) != -1:
            lst.append([e.find(i,k),e.find(i,k)+len(i)])
            k = e.find(i,k)+len(i)
        k = 0
    lst.sort()
    lst.append([len(s),len(s)])
    str = ""
    o = 0
    for i in range(len(lst)):
        str += s[o:lst[i][0]]+highlight(s[lst[i][0]:lst[i][1]])
        o = lst[i][1]
    return(str)
def display_tag_file(filename):
    f = open(filename, 'r', encoding='utf-8')
    str = f.read()
    while str.find("</>") != -1:
        l = 1
        while "<red>" not in str[str.find("</>")-l:str.find("</>")] and "<green>" not in str[str.find("</>")-l:str.find("</>")] and "<blue>" not in str[str.find("</>")-l:str.find("</>")]:
            l = l+1
        str = str[:str.find("</>")-l]+color_tag(str[str.find("</>")-l:str.find("</>")+3])+str[str.find("</>")+3:]
    print(str)

6530086621: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_21.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display0.0
[abc[;3, 8, 11, 13, 'mrrrpkk
ded'], f[21, ;328, 31, 33, 'mgggocreen'], 
xyz[41, ;347, 5mbbb[0, 52, 'mablue'], c
abcrrr[60, 65, 68, 70, 'red'], mpf[7;3, 82mggg[0, 8mo[;3, 85, 'g1mreen'], [87, 92, 94, 96, 'red'], [98, 10mz[;34, 1mbbb[07, 109, 'mablue']]c
[]
bytecount: {'code': 712, 'const': 452, 'code+const': 1164}
def red(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return RED+s+RESET
# --------------------------------------------------
def green(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return GREEN+s+RESET
# ---------------------------------------------------
def blue(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return BLUE+s+RESET
# ---------------------------------------------------
def highlight(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return HIGHLIGHT+s+RESET
# ---------------------------------------------------
def color_text(s, color):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    if color.lower()=='red': return red(s)
    elif color.lower()=='green': return green(s)
    elif color.lower()=='blue': return blue(s)
# ---------------------------------------------------
def color_tag(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    ans = ''
    L = []
    i=0
    while i<len(s)-1:
      i = s.find('<',i)
      if i==-1:break
      x1 = s.find('>',i)
      x2 = s.find('<',x1)
      x3 = s.find('>',x2)
      c = s[i+1:x1]
      t = s[x1+1:x2]
      L.append([i,x1+1,x2,x3,c])
      i = x3
    print(L)
    i=0
    for x,x0,x1,x2,co in L:
      ans+=s[i:x]
      ans+=color_text(s[x0:x1],co)
      i = x2+1
    ans+=s[i:]
    return ans
# ---------------------------------------------------
def highlight_words(s, words):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    L = []
    ans = ''
    ss = s
    s = s.lower()
    for word in words:
      word=word.lower()
      i=0
      while i<len(s)-1:
        if s.find(word,i)==-1: break
        L.append([s.find(word,i),s.find(word,i)+len(word)])
        i = s.find(word,i)+len(word)
    L.sort()
    i=0
    for x0,x1 in L:
      ans+=ss[i:x0]
      ans+=highlight(ss[x0:x1])
      i = x1
    ans+=ss[i:]
    return ans
# ---------------------------------------------------
def display_tag_file(filename):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    c = ''
    f = open(filename, 'r', encoding='utf-8')
    for line in f:
      c+=line
    return color_tag(c)

6530087221: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display0.0
abcrrrpkk

defgggocr

xyzbbbabc

abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 426, 'const': 871, 'code+const': 1297}
def red(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return('\033[;31m' + s + '\033[0m')
# ---------------------------------------------------
def green(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return('\033[;32m' + s + '\033[0m')
# ---------------------------------------------------
def blue(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return('\033[;34m' + s + '\033[0m')
# ---------------------------------------------------
def highlight(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return('\033[;103m' + s + '\033[0m')
# ---------------------------------------------------
def color_text(s, color):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    color = color.lower()
    if color == 'red' :
        return(red(s))
    elif color == 'blue' :
        return(blue(s))
    elif color == 'green' :
        return(green(s))
    else :
        return(s)
# ---------------------------------------------------
def color_tag(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    if "<red>" in s :
        s = s.replace('<red>','')
        s = s.replace('</>','')
        return(red(s))
    if "<green>" in s :
        s = s.replace('<green>','')
        s = s.replace('</>','')
        return(green(s))
    if "<blue>" in s :
        s = s.replace('<blue>','')
        s = s.replace('</>','')
        return(blue(s))
# ---------------------------------------------------
def highlight_words(s, words):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    for i in words :
        s = s.replace(i,highlight(i))
    return(s)
# ---------------------------------------------------
def display_tag_file(filename):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    source = open(filename,'r', encoding='utf-8')
    for line in source :
        line = line.replace("<red>","\033[;31m",).replace("<green>","\033[;32m").replace("<blue>","\033[;34m").replace("</>","\033[0m")
        print(line)

6530088921: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_21.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display1.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 792, 'const': 666, 'code+const': 1458}
def red(text):
    return (RED+text+RESET)
# ---------------------------------------------------
def green(text):
    return (GREEN+text+RESET)
# ---------------------------------------------------
def blue(text):
    return (BLUE+text+RESET)
# ---------------------------------------------------
def highlight(text):
    return (HIGHLIGHT+text+RESET)
# ---------------------------------------------------
def color_text(text,color):
    return check_color(text,color)
# ---------------------------------------------------
def color_tag(text):
    return check_tag(text)
# ---------------------------------------------------
def highlight_words(text, words):
    return highlight_sentence(text,words)
# ---------------------------------------------------
def display_tag_file(filename):
    file = open(filename, 'r', encoding="utf-8")
    answer = ''
    for i in file:
        i = i.replace('<red>',RED)
        i = i.replace('<green>',GREEN)
        i = i.replace('<blue>',BLUE)
        i = i.replace('</>',RESET)
        answer += i 
    print(answer)
# ---------------------------------------------------
def check_color(text,color):
    if color.lower() == 'red': return red(text)
    elif color.lower() == 'green': return green(text)
    elif color.lower() == 'blue': return blue(text)
    else : return(text)
# ---------------------------------------------------
def check_tag(text):
    x,y,retext = text.index('>'),text.index('</>'),''
    if '<red>' in text :
        return red(text[x+1:y])
    elif '<green>' in text :
        return green(text[x+1:y])
    elif '<blue>' in text :
        return blue(text[x+1:y])
    else :
        return text[x+1:y]
# ---------------------------------------------------
def highlight_sentence(text,words):
    if len(words) == 0 : return text
    else :
        for i in words :
            lowertext,pos,lowerwords,cal_text, = text.lower(),None,i.lower(),''
            if lowerwords not in lowertext :
                break
            else :
                for k in range(0, len(lowertext)):
                    if lowertext.find(lowerwords,k) == -1 :
                        cal_text = cal_text + text[pos+len(text[pos:pos+len(i)]):]
                        break
                    else :
                        if lowertext.find(lowerwords,k) != pos:
                            pos = lowertext.find(lowerwords,k)
                            if k == 0 : cal_text = cal_text + text[k:pos] + highlight(text[pos:pos + len(i)])
                            else : cal_text = cal_text + text[k+len(lowerwords)-1:pos] + highlight(text[pos:pos+len(i)])
                        else : pass
            text = cal_text
    return text
# ---------------------------------------------------

6530089521: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_10.0
['\x1b[;103m\x1b[;103m\x1b[;103m\x1b[;103mabc\x1b[0m\x1b[0m\x1b[0m\x1b[0mde\x1b[;103m\x1b[;103m\x1b[;103m\x1b[;103m\x1b[;103m\x1b[;103m\x1b[;103m\x1b[;103m\x1b[;103m\x1b[;103m\x1b[;103m\x1b[;103m\x1b[;103m\x1b[;103m\x1b[;103m\x1b[;103m\x1b[;103m\x1b[;103m\x1b[;103m\x1b[;103m\x1b[;103m\x1b[;103mfg\x1b[0m\x1b[0m\x1b[0m\x1b[0m\x1b[0m\x1b[0m\x1b[0m\x1b[0m\x1b[0m\x1b[0m\x1b[0m\x1b[0m\x1b[0m\x1b[0m\x1b[0m\x1b[0m\x1b[0m\x1b[0m\x1b[0m\x1b[0m\x1b[0m\x1b[0m\x1b[;103m\x1b[;103m\x1b[;103m\x1b[;103mabc\x1b[0 ... (more)
test_highlight_20.0
['aBCde\x1b[;103maBC\x1b[;103mde\x1b[;103mfg\x1b[;103m\x1b[;103m\x1Ab[;103mfgc\x1b[0m\x1Ab[0m\x1b[0m\x1cb[0mf\x1b[;103mfG\x1b[0mAbcAbbcbffGcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display0.0
abcrrrpkk

defgggocr

xyzbbbabc

abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 694, 'const': 470, 'code+const': 1164}
def red(s):
    return RED+s+RESET
# ---------------------------------------------------
def green(s):
    return GREEN+s+RESET
# ---------------------------------------------------
def blue(s):
    return BLUE+s+RESET
# ---------------------------------------------------
def highlight(s):
    return HIGHLIGHT+s+RESET
# ---------------------------------------------------
def color_text(s, color):
    color=color.lower()
    if color == 'red':
        return red(s)
    elif color =='green':
        return green(s)
    elif color =='blue':
        return blue(s)
# ---------------------------------------------------
def color_tag(s):
    for i in range (len(s)-7):
        if s[i:i+5]=='<red>':
            x=s[i+5:].find('</>')
            s=s.replace(s[i:i+x+8],red(s[i+5:i+x+5]))
        if s[i:i+7]=='<green>':
            x=s[i+7:].find('</>')
            s=s.replace(s[i:i+x+10],green(s[i+7:i+x+7]))
        if s[i:i + 6] == '<blue>':
            x = s[i + 6:].find('</>')
            s = s.replace(s[i:i + x + 9], blue(s[i + 6:i + x + 6]))
    return s
# ---------------------------------------------------
def highlight_words(s, words):
    if len(words)>0:
        for k in range(len(words)):
            word=words[k]
            for i in range (len(s)-4):
                if s[i:i+len(word)]== word:
                    s=s.replace(s[i:i+len(word)],highlight(s[i:i+len(word)]))
        return  s
    else: return s
# ---------------------------------------------------
def display_tag_file(filename):
    k=open(filename , 'r', encoding='utf-8')
    for i in k:
        print(color_tag(i))

6530090021: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_21.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display1.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 634, 'const': 778, 'code+const': 1412}
def red(s):
    x = '\033[;31m'+s+'\033[0m'
    return x
def green(s):
    x = '\033[;32m'+s+'\033[0m'
    return x
def blue(s):
    x = '\033[;34m'+s+'\033[0m'
    return x
def highlight(s):
    x = '\033[;103m'+s+'\033[0m'
    return x
def color_text(s, color):
    if color.lower() == 'red':
        return red(s)
    elif color.lower() == 'green':
        return green(s)
    elif color.lower() == 'blue':
        return blue(s)
    else:
        return s
def color_tag(s):
    color = ''
    ans = ''    
    for i in s:       
        if i == '<' :
            break 
        ans += i
    s = s[len(ans):]
    name = ''
    isColor = True    
    for i in range(len(s)):           
        if s[i] == '<' :            
            ans += color_text(name, color)
            name = ''
            color = ''
            isColor = True
        elif s[i].lower() in 'abcdefghijklmnopqrstuvwxyz':
            if isColor :
                color += s[i]
            else :
                name += s[i]
        elif s[i] == '>' :
            isColor = False
        elif s[i] not in '</>'  :
            name += s[i]
    ans += name
    return  ans
def highlight_words(s, words):
    ans = ''    
    i = 0
    for l in words:
        while i < len(s) :
            if s[i:i+len(l)].lower() == l.lower() :
                ans += '\033[;103m'+s[i:i+len(l)]+'\033[0m'
                i += len(l) -1
            else :
                ans += s[i]
            i += 1
        s = ans
        ans = ''
        i = 0
    return s
def display_tag_file(filename):
    f = open(filename, 'r', encoding="utf-8")
    data = f.read()    
    f.close()
    print(color_tag(data))

6530091721: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display0.0
abcrrrpkk

defgggocr

xyzbbbabc

abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 676, 'const': 610, 'code+const': 1286}
def red(s):
  s=RED+s
  return s+RESET
# ---------------------------------------------------
def green(s):
  s=GREEN+s
  return s+RESET
# ---------------------------------------------------
def blue(s):
  s=BLUE+s
  return s+RESET
# ---------------------------------------------------
def highlight(s):
  s=HIGHLIGHT+s
  return s+RESET
# ---------------------------------------------------
def color_text(s, color):
  w=color.lower()
  if w=='red':
    a=red(s)
  elif w=='green':
    a=green(s)
  elif w=='blue':
    a=blue(s)
  else:
    a=s
  return a
# ---------------------------------------------------
def color_tag(s):
  a=s.find('>')
  b=s.find('/')
  z=s
  if 'red' in s[:a]:
    z=red(s[a+1:b-1])
  elif 'blue' in s[:a]:
    z=blue(s[a+1:b-1])
  elif 'green' in s[:a]:
    z=green(s[a+1:b-1])
  return z
# ---------------------------------------------------
def highlight_words(s, words):
  for i in words :
    s=s.split(i)
    d=HIGHLIGHT+i+RESET
    s=d.join(s)
  return s
# ---------------------------------------------------
def display_tag_file(filename):
  g=open(filename, 'r', encoding='utf-8')
  for line in g :
    a=line.replace('<',',').replace('>',',')
    a=a.split(',')
    for s in a :
      if s=='red':
        d=a.index(s)
        a.remove(s)
        a.remove('/')
        a[d]=red(a[d])
      elif s=='green':
        d=a.index(s)
        a.remove(s)
        a.remove('/')
        a[d]=green(a[d])
      elif s=='blue':
        d=a.index(s)
        a.remove(s)
        a.remove('/')
        a[d]=blue(a[d])
    a=''.join(a)
    print(a)

6530092321: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_21.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display1.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 674, 'const': 578, 'code+const': 1252}
def red(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return RED + s + RESET
# ---------------------------------------------------
def green(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return GREEN + s + RESET
# ---------------------------------------------------
def blue(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return BLUE + s + RESET
# ---------------------------------------------------
def highlight(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return HIGHLIGHT + s + RESET
# ---------------------------------------------------
def color_text(s, color):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    color = color.upper()
    if color == 'RED':
        return red(s)
    elif color == 'GREEN':
        return green(s)
    elif color == 'BLUE':
        return blue(s)
    else:
        return s
# ---------------------------------------------------
def color_tag(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    s_index = 0
    #return [start_index, end_index, color, ...]
    while True:
        s_index = s.find('>', s_index)
        if s_index == -1:
            break
        if s[s_index-1] != '/':
            start_index = s_index+1
        elif s[s_index-1] == '/':
            if s[start_index-2] == 'd':
                s = s[:start_index-5] + color_text(s[start_index:s_index-2], 'red') + s[s_index+1:]
            elif s[start_index-2] == 'n':
                s = s[:start_index-7] + color_text(s[start_index:s_index-2], 'green') + s[s_index+1:]
            elif s[start_index-2] == 'e':
                s = s[:start_index-6] + color_text(s[start_index:s_index-2], 'blue') + s[s_index+1:]
        s_index += 1
    return s
# ---------------------------------------------------
def highlight_words(s, words):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    for i in words:
        s_index = 0
        while True:
            s_index = s.lower().find(i.lower(), s_index)
            if s_index == -1:
                break
            s = s[:s_index] + highlight(s[s_index:s_index+len(i)]) + s[s_index+len(i):]
            s_index += len(highlight(s[s_index:s_index+len(i)]))
    return s
# ---------------------------------------------------
def display_tag_file(filename):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    txt = open(filename, 'r', encoding='utf-8')
    print(color_tag(txt.read()))

6530094621: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_10.0 web = open(filename , 'r', encoding='utf-8')
^
IndentationError: expected an indented block
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0 web = open(filename , 'r', encoding='utf-8')
^
IndentationError: expected an indented block
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display0.0 web = open(filename , 'r', encoding='utf-8')
^
IndentationError: expected an indented block
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {}
def red(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return '\033[;31m' + s + '\033[0m'
# ---------------------------------------------------
def green(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return '\033[;32m' + s + '\033[0m'
# ---------------------------------------------------
def blue(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return '\033[;34m' + s + '\033[0m'
# ---------------------------------------------------
def highlight(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return '\033[;103m' + s + '\033[0m'
# ---------------------------------------------------
def color_text(s, color):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    color = color.lower()
    if color == "red" :
        return red(s)
    elif color == "blue" :
        return blue(s)
    elif color == "green" :
        return green(s)
    else :
        return s
# ---------------------------------------------------
def color_tag(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    if s[1:4] == "red" :
        return red(s[5:-3])
    elif s[1:6] == "green" :
        return green(s[7:-3])
    elif s[1:5] == "blue" :
        return blue(s[6:-3])
# ---------------------------------------------------
def highlight_words(s, words):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    for e in words :
        t = s.lower().find(e.lower())
        c = t
        while t >= 0 :
            s = s[:c] + highlight(s[c:c+len(e)]) + s[c+len(e):]
            t = s.lower()[c+10+len(e):-1].find(e.lower())
            c += t + 10 + len(e)          
    return s
# ---------------------------------------------------
def display_tag_file(filename):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    def display_tag_file(filename) :
    web = open(filename , 'r', encoding='utf-8')
    ans = ""
    for line in web :
        ans = line.split("\n")
        ans = ans[0]
        for color in ["<red>", "<blue>", "<green>"] :
            c = ans.find(color)
            t = c
            c2 = 0
            while (t != -1):
                c2 = ans.find("</>",c)
                #print (c, c2, ans[c:c2])
                if color == "<red>":
                    ans = ans[:c] + '\033[;31m' + ans[c+len(color):c2] + '\033[0m' + ans[c2+3:]
                elif color == "<blue>":
                    ans = ans[:c] + '\033[;34m' + ans[c+len(color):c2] + '\033[0m' + ans[c2+3:]
                elif color == "<green>":
                    ans = ans[:c] + '\033[;32m' + ans[c+len(color):c2] + '\033[0m' + ans[c2+3:]
                t = ans[c+10+len(ans[c+len(color):c2]):-1].find(color)
                c += t + 10 + len(ans[c+len(color):c2])
                #print (t , c, c2)
        print(ans)
    #         print(line)
    #         print(line.split("<"))
    web.close()

6530095221: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_10.0TypeError('join() takes exactly one argument (0 given)')
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0TypeError('join() takes exactly one argument (0 given)')
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display0.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 382, 'const': 640, 'code+const': 1022}
def red(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return "\033[;31m" + s + "\033[0m"
# ---------------------------------------------------
def green(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return "\033[;32m" + s + "\033[0m"
# ---------------------------------------------------
def blue(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return "\033[;34m" + s + "\033[0m"
# ---------------------------------------------------
def highlight(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return "\033[;103m" + s + "\033[0m"
# ---------------------------------------------------
def color_text(s, color):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    if color == "red":
      return red(s)
    elif color == "GreeN":
        return green(s)
    elif color == "BLUE":
      return blue(s)
    return s 
# ---------------------------------------------------
def color_tag(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    tags = ["<red>", "<green>", "<blue>"]
    q = "</>"
    k = s.find(">")
    m = s.find("<",2)
    w = s[k+1:m]
    if tags[0] in s:
      return RED + w + RESET
    elif tags[1] in s:
      return GREEN + w + RESET
    elif tags[2] in s:
      return BLUE + w + RESET
# ---------------------------------------------------
def highlight_words(s, words):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    for w in words:
      if w in s:
        x = s.split(w[:])
        for e in x:
          d = HIGHLIGHT + w + RESET
          k = "".join()
      return 
# ---------------------------------------------------
def display_tag_file(filename):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    pass
#test1

6530096921: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display1.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 786, 'const': 663, 'code+const': 1449}
def red(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return RED+s+RESET
# ---------------------------------------------------
def green(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return GREEN+s+RESET
# ---------------------------------------------------
def blue(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return BLUE+s+RESET
# ---------------------------------------------------
def highlight(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return HIGHLIGHT+s+RESET
# ---------------------------------------------------
def color_text(s, color):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    c=color.lower()
    if c == 'red':
        return RED+s+RESET
    elif c=='green':
        return GREEN+s+RESET
    elif c=='blue':
        return BLUE+s+RESET
    else: return s
# ---------------------------------------------------
def color_tag(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    if s.find("<red>") != -1:
        i=s.find("<red>")
        j=s.find("</>")
        return RED + s[i+5:j] + RESET
    elif s.find("<green>") != -1:
        i=s.find("<green>")
        j=s.find("</>")
        return GREEN + s[i+7:j] + RESET
    elif s.find("<blue>") != -1:
        i=s.find("<blue>")
        j=s.find("</>")
        return BLUE + s[i+6:j] + RESET
# ---------------------------------------------------
def highlight_words(s, words):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    out=""
    if len(words)>0:
        for w in words:
            s=s.split(w)#ด้ ฟหก เาสว
            hw=HIGHLIGHT+w+RESET
            s=hw.join(s)
            out=s
    else:
        out=s
    return out
# ---------------------------------------------------
def display_tag_file(filename):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    infile=open(filename,"r",encoding='utf-8')
    out=""
    c=[]
    x=""
    for line in infile:
        out+=line
    a=out.split("<"or"</>")  #aคือลิสของตนส.ที่วรรค
    for ch in a:
        ch="<"+ch+"</>"
        if ch.find('red')!=-1 or ch.find('green')!=-1 or ch.find('blue')!=-1:
            c.append(color_tag(ch)) #c=ตนส.ที่มีสี
    for i in range(0,len(a)): #ของa
        if i==0:
            x+=a[i]+c[i]
        elif i%2 ==0 and (i//2)<len(c):
            A=a[i][2:]
            x+=A+c[i//2]
        elif i%2 ==0 and (i//2)>len(c):
            x+=A+c[len(c)]
    x+=a[-1][2:]
    infile.close()
    print(x)

6530097521: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0
['\x1b[;103mabcBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103maAbc\x1b[0mAbbcbf\x1b[;103mfgG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display1.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 530, 'const': 708, 'code+const': 1238}
def red(s):
    return "\033[;31m" + s + "\033[0m"
# ---------------------------------------------------
def green(s):
    return "\033[;32m" + s + "\033[0m"
# ---------------------------------------------------
def blue(s):
    return "\033[;34m" + s + "\033[0m"
# ---------------------------------------------------
def highlight(s):
    return "\033[;103m" + s + "\033[0m"
# ---------------------------------------------------
def color_text(s, color):
    if color.lower() == "red":
        return red(s)
    if color.lower() == "green":
        return green(s)
    if color.lower() == "blue":
        return blue(s)
    else:
        return s
# ---------------------------------------------------
def color_tag(s):
    ftag = s.find(">")
    fs = s.find("</>",ftag)
    return color_text(s[ftag+1:fs],s[1:ftag])
# ---------------------------------------------------
def highlight_words(s, words):
    ns = ""
    news =  ""
    for i in s:
        ns += i
        for n in words:
            if n.lower() in ns.lower():
                news += ns[:-len(n)] + highlight(n)
                ns = ""
    return news + ns
# ---------------------------------------------------
def display_tag_file(filename):
    fin = open(filename, 'r', encoding='utf-8')
    new = ""
    neww = ""
    sen = ""
    for line in fin:
        new += line
    for i in new:
        neww += i
        if "</>" in neww:
            stag = neww.find("<")
            ftag = neww.find(">")
            fs = neww.find("</>",ftag)
            sen += neww[0:stag] + color_text(neww[ftag+1:fs],neww[stag+1:ftag])
            neww = ""
    fin.close()
    print(sen + neww)

6530098121: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_10.0NameError("name 'text' is not defined")
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0NameError("name 'text' is not defined")
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display1.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 626, 'const': 626, 'code+const': 1252}
def red(s):
    return RED + s + RESET
# ---------------------------------------------------
def green(s):
    return GREEN + s + RESET
# ---------------------------------------------------
def blue(s):
    return BLUE + s + RESET
# ---------------------------------------------------
def highlight(s):
    return HIGHLIGHT + s + RESET
# ---------------------------------------------------
def color_text(s, color):
    color = color.lower()
    if color == "green":
        return green(s)
    elif color == "red":
        return red(s)
    elif color == "blue":
        return blue(s)
    else:
        return "s"
# ---------------------------------------------------
def color_tag(s):
    if "red" == s[1:4]:
        return red(s[5:len(s)-2])
    elif "green" == s[1:6]:
        return green(s[7:len(s)-2])
    elif "blue" == s[1:5]:
        return blue(s[6:len(s)-2])
# ---------------------------------------------------
def highlight_words(s, words):
    for i in words:
        s = s.replace(i,highlight(i))
    return text
# ---------------------------------------------------
def display_tag_file(filename):
    f = open(filename, 'r', encoding='utf-8')
    str = f.read()
    x = str.split("</>")
    k = ""
    for i in x:
        if "<red>" in i:
            i = i.replace(i[i.find("<red>"):],red(i[i.find("<red>")+5:]))
            k += i
        elif "<green>" in i:
            i = i.replace(i[i.find("<green>"):],green(i[i.find("<green>")+7:]))
            k += i
        elif "<blue>" in i:
            i = i.replace(i[i.find("<blue>"):],blue(i[i.find("<blue>")+6:]))
            k += i
        else:
            k += i
    print(k)

6530099821: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display0.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 462, 'const': 401, 'code+const': 863}
def red(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    a=RED+s+RESET
    return a
# ---------------------------------------------------
def green(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    a=GREEN+s+RESET
    return a
# ---------------------------------------------------
def blue(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    a=BLUE+s+RESET
    return a
# ---------------------------------------------------
def highlight(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    a=HIGHLIGHT+s+RESET
    return a
# ---------------------------------------------------
def color_text(s,color):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    if color.lower()=='red':
      return red(s)
    if color.lower()=='green':
      return green(s)
    if color.lower()=='blue':
      return blue(s)
# ---------------------------------------------------
def color_tag(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    a=s.split('</>')
    j=''
    for i in a:
        if '<red>' in i:
            i=i.split('<red>')
            i[1]=red(i[1])
            j+=''.join(i)
        elif '<blue>' in i:
            i=i.split('<blue>')
            i[1]=blue(i[1])
            j+=''.join(i)
        elif '<green>' in i:
            i=i.split('<green>')
            i[1]=green(i[1])
            j+=''.join(i)
        else:
            j+=i
    return j
# -------------------------------------------------
def highlight_words(s, words):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    for word in words:
        s = s.replace(word,highlight(word))
    return s
# ---------------------------------------------------
def display_tag_file(filename):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    file = open(filename, 'r', encoding='utf-8')
    return color_tag(file.read())
#t = 'a[3]มิใช่ลิสต์ คืนค่ามิใช่print =มิใช่เปรียบเทียบ รักมิใช่ดวงดาวที่พราวแสง'
#print(highlight_words(t,['มิใช่']))

6530100721: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display0.0
abcrrrpkk

defgggocr

xyzbbbabc

abcrrrpfgggorrzbbbabcabc
[]
bytecount: {'code': 594, 'const': 1063, 'code+const': 1657}
def red(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    red = '\033[;31m' + s + '\033[0m'
    return red
# ---------------------------------------------------
def green(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    green = '\033[;32m' + s + '\033[0m'
    return green
# ---------------------------------------------------
def blue(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    blue = '\033[;34m' + s + '\033[0m'
    return blue
# ---------------------------------------------------
def highlight(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    highlight = '\033[;103m' + s + '\033[0m'
    return highlight
# ---------------------------------------------------
def color_text(s, color):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    color = color.lower()
    if color == 'red':
        text = '\033[;31m' + s + '\033[0m'
    elif color == 'green':
        text = '\033[;32m' + s + '\033[0m'
    elif color == 'blue':
        text = '\033[;34m' + s + '\033[0m'
    else:
        text = s
    return text
# ---------------------------------------------------
def color_tag(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    tag = s.replace('<',',').replace('>',',')
    tag = tag.strip(',')
    tag = tag.split(',')
    tag = color_text(tag[1],tag[0])
    return tag
# ---------------------------------------------------
def highlight_words(s, words):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    for word in words:
        if word in s:
            s = s.split(word)
            s = ('\033[;103m' + word+ '\033[0m').join(s)
    return s
# ---------------------------------------------------
def display_tag_file(filename):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    final = open(filename,'r', encoding='utf-8')
    for line in final :
      if '<red>' in line :
        start = '<red>'
        end = '</>'
        word = (line.split(start))[1].split(end)[0]
        line = line.replace('<red>','').replace(word,'\033[;31m' + word + '\033[0m').replace('</>','')
      if '<green>' in line :
        start = '<green>'
        end = '</>'
        word = (line.split(start))[1].split(end)[0]
        line = line.replace('<green>','').replace(word,'\033[;32m' + word + '\033[0m').replace('</>','')
      if '<blue>' in line :
        start = '<blue>'
        end = '</>'
        word = (line.split(start))[1].split(end)[0]
        line = line.replace('<blue>','').replace(word,'\033[;34m' + word + '\033[0m').replace('</>','')
      print(line)

6530101321: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display0.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 354, 'const': 343, 'code+const': 697}
def red(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    rword = RED + s + RESET
    return rword
# ---------------------------------------------------
def green(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    gword = GREEN + s + RESET
    return gword
# ---------------------------------------------------
def blue(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    bword = BLUE + s + RESET
    return bword
# ---------------------------------------------------
def highlight(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    hlword = HIGHLIGHT + s + RESET
    return hlword
# ---------------------------------------------------
def color_text(s, color):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    if len(color) == 3 :
        text = red(s)
    elif len(color) == 5 :
        text = green(s)
    elif len(color) == 4 :
        text = blue(s)
    else : return s
    return text
# ---------------------------------------------------
def color_tag(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    if "<red>" in s :
        text = red(s[5:-3])
    elif "<green>" in s :
        text = green(s[7:-3])
    elif "<blue>" in s :
        text = blue(s[6:-3])
    return text
# ---------------------------------------------------
def highlight_words(s, words):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    for x in words :
        s = s.replace(x,highlight(x))
    return s
# ---------------------------------------------------
def display_tag_file(filename):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    open(filename, 'r', encoding='utf-8')

6530102021: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_10.0
['\x1b[;103mabc\x1b[0mdefg\x1b[;103mabcfg\x1b[0mgabcabbcbffgcd\x1b[;103mabc\x1b[0mcabbcbffgcdabcaa\x1b[;103mabcfg\x1b[0mcd\x1b[;103mfgabc\x1b[0mbfaa\x1b[;103mfgabc\x1b[0mcdabcaaabc']
test_highlight_20.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfgA\x1bcAbbcbffGcd[0m\x1b[;103maAbc\x1b[0mdefgAbcAbbcbf\x1b[;103mfGcda\x1b[0mcaad\x1b[;103mabc\x1b[0maa\x1b[;103mfgabc\x1b[0mAbbcbffGcdabcaaabc']
test_display1.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 628, 'const': 907, 'code+const': 1535}
def red(s):
  return '\033[;31m' + s + '\033[0m'
# ---------------------------------------------------
def green(s):
    return '\033[;32m' + s + '\033[0m'
# ---------------------------------------------------
def blue(s):
   return '\033[;34m' + s + '\033[0m'
# ---------------------------------------------------
def highlight(s):
    return '\033[;103m' + s + '\033[0m'
# ---------------------------------------------------
def color_text(s, color):
  color = color.lower()
  if color == 'red':
    return red(s)
  elif color == 'green':
    return green(s)
  elif color == 'blue':
    return blue(s)
# ---------------------------------------------------
def color_tag(s):
    a = s.find('<')
    b = s.find('>')
    c = s.find('/')
    if s[a+1:b] == 'red':
      te = s[b+1:c-1]
      return red(te)
    elif s[a+1:b] == 'green':
      te = s[b+1:c-1]
      return green(te)
    elif s[a+1:b] == 'blue':
      te = s[b+1:c-1]
      return blue(te)
# ---------------------------------------------------
def highlight_words(s, words):
  long  = []
  sen1 = ''
  time = 0
  for e in words:
      long.append(len(e))
  for a in long:
      for i in range(len(s)) :
          if s[i:i+a] in words:
              sen1 += s[time:i]
              sen1 += '\033[;103m' + s[i:i+a] + '\033[0m'
              time += a
          else:
              pass
  sen1 += s[time+a:]
  return sen1
# ---------------------------------------------------
def display_tag_file(filename):
  ans =''
  line = open(filename, 'r', encoding='utf-8')
  for lines in line :
    lines = lines.replace('<red>',RED)
    lines = lines.replace('<green>',GREEN)
    lines = lines.replace('<blue>',BLUE)
    lines = lines.replace('</>',RESET)
    ans +=lines 
  print(ans)

6530103621: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display0.0FileNotFoundError("No such file or directory: 'มหาจุฬาลงกรณ์-tag.txt'")
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 746, 'const': 684, 'code+const': 1430}
def red(s):
    return f'{RED}{s}{RESET}'
# ---------------------------------------------------
def green(s):
    return f'{GREEN}{s}{RESET}'
# ---------------------------------------------------
def blue(s):
    return f'{BLUE}{s}{RESET}'
# ---------------------------------------------------
def highlight(s):
    return f'{HIGHLIGHT}{s}{RESET}'
# ---------------------------------------------------
def color_text(s, color):
    if color.upper() == 'RED':
        color = RED
    elif color.upper() == 'GREEN':
        color = GREEN
    elif color.upper() == 'BLUE':
        color = BLUE
    else:
        color = RESET
    return f'{color}{s}{RESET}'
# ---------------------------------------------------
def color_tag(s):
    if s[:5] == '<red>':
        s = s[5:-3]
        color = RED
    elif s[:7] == '<green>':
        s = s[7:-3]
        color = GREEN
    elif s[:6] == '<blue>':
        s = s[6:-3]
        color = BLUE
    return f'{color}{s}{RESET}'
# ---------------------------------------------------
def highlight_words(s, words):
    if len(words) != 0 :
        for e in words :
            if e.lower() in s.lower():
                words_new = f'{HIGHLIGHT}{e}{RESET}'
                s = s.replace(e, words_new)
    return s
# ---------------------------------------------------
def display_tag_file(filename):
    fin = open('มหาจุฬาลงกรณ์-tag.txt', 'r', encoding='utf-8')
    for line in fin:
        if "<red>" in line :
            g1 = line.find("<red>")
            g2 = line.find("</>",g1+1)
            line_new = f'{RED}{line[g1+5:g2]}{RESET}'
            line = line.replace(line[g1+5:g2],line_new)
        if "<green>" in line :
            g3 = line.find("<green>")
            g4 = line.find("</>",g3+1)
            line_new = f'{GREEN}{line[g3+7:g4]}{RESET}'
            line = line.replace(line[g3+7:g4],line_new)
        if "<blue>" in line :
            g5 = line.find("<blue>")
            g6 = line.find("</>",g5+1)
            line_new = f'{BLUE}{line[g5+6:g6]}{RESET}'
            line = line.replace(line[g5+6:g6],line_new)
        line = line.replace("<red>","")
        line = line.replace("<green>","")
        line = line.replace("<blue>","")
        line = line.replace("</>","")
        print(line)
    fin.close()

6530104221: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display1.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 504, 'const': 567, 'code+const': 1071}
def red(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return RED+s+RESET
# ---------------------------------------------------
def green(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return GREEN+s+RESET
# ---------------------------------------------------
def blue(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return BLUE+s+RESET
# ---------------------------------------------------
def highlight(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return HIGHLIGHT+s+RESET
# ---------------------------------------------------
def color_text(s, color):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    if color.lower()=='red':
        return red(s)
    elif color.lower()=='green':
        return green(s)
    elif color.lower()=='blue':
        return blue(s)
    else:
        return s
# ---------------------------------------------------
def color_tag(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    s=s.split('>')
    color=s[0][1:] ; s=s[1][:-2]
    if color=='red':
        return red(s)
    elif color=='blue':
        return blue(s)
    elif color=='green':
        return green(s)
    else:
        return s
# ---------------------------------------------------
def highlight_words(s, words):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    for e in words:
        list_s = s.split(e)
        s=''
        for i,a in enumerate(list_s):
          if i!= len(list_s)-1:
            s+=a+highlight(e)
        else:
            s+=a
    return s
# ---------------------------------------------------
def display_tag_file(filename):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    fin = open(filename, 'r', encoding='utf-8').read()
    fin = fin.split('<')
    out=''
    for i,a in enumerate(fin):
      if i%2==0:
        out+=a.replace('/>','')
      else:
        out+=color_tag('<'+a+'</>')
    print(out)

6530105921: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_21.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display1.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 700, 'const': 622, 'code+const': 1322}
def red(s):
    return RED + s + RESET    #print(red("sas"))
# ---------------------------------------------------
def green(s):
    return GREEN + s + RESET
# ---------------------------------------------------
def blue(s):
    return BLUE + s + RESET
# ---------------------------------------------------
def highlight(s):
    return HIGHLIGHT + s + RESET
# ---------------------------------------------------
def color_text(s,color):     #print(color_text("sasdd","Green"))
    color = color.lower()
    s_changed = ""
    if color == 'red':
        s_changed = RED + s + RESET
    elif color == 'green':
        s_changed = GREEN + s + RESET
    elif color == 'blue':
        s_changed = BLUE + s + RESET
    else:
        s_changed = s
    return s_changed
# ---------------------------------------------------
def color_tag(s):    #print(color_tag("<green>green text</>"))
    a = s[1::]
    a = a[:-3]
    color,s = a.split(">")
    color = color.lower()
    s_changed = ""
    if color == 'red':
        s_changed = RED + s + RESET
    elif color == 'green':
        s_changed = GREEN + s + RESET
    elif color == 'blue':
        s_changed = BLUE + s + RESET
    else:
        s_changed = s
    return s_changed
# ---------------------------------------------------
def highlight_words(s, words):  #print(highlight_words(t, ['kOUy','ey']))
    wordch = []
    for a in words:
        wordch += [a.lower()]
    sch = s.lower()
    b = 0
    j = []
    n = 0
    for k in wordch:    
        while n != -1:
            n = sch.find(k,b)
            j += [n]
            b = n + 1
        j = j[:-1:]
        j = j[::-1]
        for e in j:
            s = s[:e:] + HIGHLIGHT + s[e:e+len(k):] + RESET + s[e+len(k)::]
            sch = sch[:e:] + HIGHLIGHT + sch[e:e+len(k):] + RESET + sch[e+len(k)::]
        j = []
        b = 0
        n = 0
    return s
# ---------------------------------------------------
def display_tag_file(filename):  #print(display_tag_file('มหาจุฬาลงกรณ์-tag.txt'))
    fn = open(filename, 'r', encoding='utf-8')
    out = ""
    for line in fn:
        out += line
    out = out.replace("<red>", RED)
    out = out.replace("</>", RESET)
    out = out.replace("<green>", GREEN)
    out = out.replace("<blue>", BLUE)
    print(out)
    fn.close()

6530106521: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display1.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 470, 'const': 533, 'code+const': 1003}
def red(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return RED+s+RESET
# ---------------------------------------------------
def green(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return GREEN+s+RESET
# ---------------------------------------------------
def blue(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return BLUE+s+RESET
# ---------------------------------------------------
def highlight(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return HIGHLIGHT+s+RESET
# ---------------------------------------------------
def color_text(s, color):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    color = color.lower()
    if color == 'red':
        return red(s)
    elif color == 'blue':
        return blue(s)
    elif color == 'green':
        return green(s)
    else:
        return s
# ---------------------------------------------------
def color_tag(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    s = s.split('>')
    color = s[0][1:]
    s = s[1][0:-2]
    return color_text(s, color)
# ---------------------------------------------------
def highlight_words(s,words):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    for word in words:
        sp = s.split(word)
        s = ''.join([a+HIGHLIGHT+word+RESET if i!= len(sp)-1 else a for i,a in enumerate(sp)])
    return s
# ---------------------------------------------------
def display_tag_file(filename):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    txt = open(filename, 'r', encoding='utf-8').read().split('<')
    print(''.join([a.replace('/>','') if i%2==0 else color_tag('<'+a+'</>') for i,a in enumerate(txt)]))

6530107121: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display0.0
abcrrrpkk

defgggocr

xyzbbbabc

abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 666, 'const': 500, 'code+const': 1166}
def red(s):
    s = RED + s + RESET
    return s
# ---------------------------------------------------
def green(s):
    s = GREEN + s + RESET
    return s
# ---------------------------------------------------
def blue(s):
    s = BLUE + s + RESET
    return s
# ---------------------------------------------------
def highlight(s):
    s = HIGHLIGHT + s + RESET
    return s
# ---------------------------------------------------
def color_text(s,color):
    color = color.lower()
    if color in ['red','green','blue']:
        if color == 'red':
            return red(s)
        if color == 'green':
            return green(s)
        if color == 'blue':
            return blue(s)  
# ---------------------------------------------------
def color_tag(s):
    k = 0
    a = s.find('</>',k)
    while a != -1:
        if '<red>' in s[:a]:
            b = s.find('<red>',k)
            s = s[:b] + red(s[b+5:a]) + s[a+3:]
            k = b          
        if '<green>' in s[:a]:
            b = s.find('<green>',k)
            s = s[:b] + green(s[b+7:a]) + s[a+3:]
            k = b              
        if '<blue>' in s[:a]:
            b = s.find('<blue>',k)
            s = s[:b] + blue(s[b+6:a]) + s[a+3:]
            k = b
        a = s.find('</>',k)
    return s
# ---------------------------------------------------
def highlight_words(s, words):
    for i in words:
        k = 0
        a = s.find(i,k)
        while a != -1:
            s = s[:a] + highlight(i) + s[a+len(i):]
            k = a+len(highlight(i))
            a = s.find(i,k)   
    return s
# ---------------------------------------------------
def display_tag_file(filename):
    a = open(filename,'r', encoding='utf-8')
    for line in a:
        print(color_tag(line))
    a.close()

6530109421: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display1.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 1068, 'const': 980, 'code+const': 2048}
def red(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return '\033[;31m'+s+'\033[0m'
# ---------------------------------------------------
def green(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return '\033[;32m'+s+'\033[0m'
# ---------------------------------------------------
def blue(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return '\033[;34m'+s+'\033[0m'
# ---------------------------------------------------
def highlight(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return '\033[;103m'+s+'\033[0m'
# ---------------------------------------------------
def color_text(s, color):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    color = color.lower()
    if color == 'red':
        return red(s)
    elif color == 'green':
        return green(s)
    elif color == 'blue':
        return blue(s)
    else:
        return s
# ---------------------------------------------------
def color_tag(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    x = s.split('>')
    if 'red' in x[0]:
        return red(x[1][:-2])
    if 'green' in x[0]:
        return green(x[1][:-2])
    if 'blue' in x[0]:
        return blue(x[1][:-2])
# ---------------------------------------------------
def highlight_words(s, words):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    t = s
    found = False
    for i in words:
        if i in s:
            found = True
            k = s.find(i)
            x = t.split(i)
            p = i[::-1]
            m = s[::-1].find(p)
            a = ''
            if k != 0 and m != 0:
                for j in range(len(x)-1):
                    a += x[j] + highlight(i)
                a += x[-1]
            if k == 0 and m != 0:
                if len(x) >= 3:
                    a += highlight(i)
                    for j in range(1,len(x)-1):
                        a += x[j] + highlight(i)
                    a += x[-1]
                else:
                    a += highlight(i) + x[1]
            if k != 0 and m == 0:
                for j in range(len(x)-1):
                    a += x[j] + highlight(i)
            if k == 0 and m == 0:
                if len(x) >= 4:
                    a = highlight(i)
                    for j in range(1,len(x)-1):
                        a += x[j] + highlight(i)
                else:
                    a += highlight(i) + x[1] + highlight(i)
            t = a
    if not found:
        a = s
    return a
# ---------------------------------------------------
def display_tag_file(filename):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    y = open(filename, 'r', encoding='utf-8')
    y = y.read()
    x = y.split('<')
    a = ''
    for i in range(len(x)):
        if 'red>' not in x[i] and 'blue>' not in x[i] and 'green>' not in x[i] and '/>' not in x[i]:
            a += x[i]
        if 'red>' in x[i]:
            a += red(x[i][4:])
        if 'blue>' in x[i]:
            a += blue(x[i][5:])
        if 'green>' in x[i]:
            a += green(x[i][6:])
        if '/>' in x[i]:
            a += x[i][2:]
    print(a)

6530110021: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_10.0IndexError('string index out of range')
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0IndexError('string index out of range')
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display0.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 1926, 'const': 936, 'code+const': 2862}
def red(s):
    s = RED+s+RESET
    return s
# ---------------------------------------------------
def green(s):
    s = GREEN+s+RESET
    return s
# ---------------------------------------------------
def blue(s):
    s = BLUE+s+RESET
    return s
# ---------------------------------------------------
def highlight(s):
    s = HIGHLIGHT+s+RESET
    return s
# ---------------------------------------------------
def color_text(s, color):
    # ชื่อสีสามารถเขียนได้ทั้งตัวเล็กหรือตัวใหญ่
    text_lower = color.lower()
    if text_lower == "red" :
        result = red(s)
    elif text_lower == "green" :
        result = green(s)
    elif text_lower == "blue" :
        result = blue(s)
    else:
      return s
    return result
# ---------------------------------------------------
def color_tag(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    text = ""
    red_check = "<red>"
    green_check = "<green>"
    blue_check = "<blue>"
    if s[0] == red_check[0] and s[1] == red_check[1] and s[2] == red_check[2] and s[3] == red_check[3] and s[4] == red_check[4]:
        for i in range(5, len(s)):
          if s[i] == "<" and s[i+1] == "/" and s[i+2] == ">":
            break
          else:
            text += red(s[i])
    elif s[0] == green_check[0] and s[1] == green_check[1] and s[2] == green_check[2] and s[3] == green_check[3] and s[4] == green_check[4] and s[5] == green_check[5] and s[6] == green_check[6]:
        for i in range(7, len(s)):
          if s[i] == "<" and s[i+1] == "/" and s[i+2] == ">":
            break
          else:
            text += green(s[i])
    elif s[0] == blue_check[0] and s[1] == blue_check[1] and s[2] == blue_check[2] and s[3] == blue_check[3] and s[4] == blue_check[4] and s[5] == blue_check[5]:
        for i in range(6, len(s)):
          if s[i] == "<" and s[i+1] == "/" and s[i+2] == ">":
            break
          else:
            text += blue(s[i])
    return text
# ---------------------------------------------------
def highlight_words(s, words):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    text = ""
    i=0
    if len(words) > 0:
      while i < len(s):
        for w in words:
          text_lower = ""
          result = ""
          for j in range(0, len(w)):
            if s[i+j].lower() == w[j].lower():
              text_lower += s[i+j].lower()
              result += s[i+j]
            else:
              text_lower = ""
              result = ""
              break
          if text_lower == w:
            text += highlight(result)
            i += len(w)
        if text_lower == "":
          text += s[i]
          i+=1
    else:
      text = s
    return text
# ---------------------------------------------------
def display_tag_file(filename):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    file = open(filename, "r", encoding='utf-8')
    data = ""
    for line in file:
      data += line
    file.close()
    text = ""
    red_check = "<red>"
    green_check = "<green>"
    blue_check = "<blue>"
    i=0
    while i < len(data):
        if data[i] == red_check[0] and data[i+1] == red_check[1] and data[i+2] == red_check[2] and data[i+3] == red_check[3] and data[i+4] == red_check[4]:
            i+=5
            words=""
            while True:
              if data[i] == "<" and data[i+1] == "/" and data[i+2] == ">":
                i+=2
                break
              else:
                words += data[i]
                i+=1
            tag = "<red>"+words+"</>"
            text += color_tag(tag)
        elif data[i] == green_check[0] and data[i+1] == green_check[1] and data[i+2] == green_check[2] and data[i+3] == green_check[3] and data[i+4] == green_check[4] and data[i+5] == green_check[5] and data[i+6] == green_check[6]:
            i+=7
            words=""
            while True:
              if data[i] == "<" and data[i+1] == "/" and data[i+2] == ">":
                i+=2
                break
              else:
                words += data[i]
                i+=1
            tag = "<green>"+words+"</>"
            text += color_tag(tag)
        elif data[i] == blue_check[0] and data[i+1] == blue_check[1] and data[i+2] == blue_check[2] and data[i+3] == blue_check[3] and data[i+4] == blue_check[4] and data[i+5] == blue_check[5]:
            i+=6
            words=""
            while True:
              if data[i] == "<" and data[i+1] == "/" and data[i+2] == ">":
                i+=2
                break
              else:
                words += data[i]
                i+=1
            tag = "<blue>"+words+"</>"
            text += color_tag(tag)
        else:
            text += data[i]
        i+=1
    return text

6530111621: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display0.0
abcrrrpkk

defgggocr

xyzbbbabc

abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 522, 'const': 925, 'code+const': 1447}
def red(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return '\033[;31m'+ s + '\033[0m'
# ---------------------------------------------------
def green(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return '\033[;32m'+ s + '\033[0m'
# ---------------------------------------------------
def blue(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return '\033[;34m'+ s + '\033[0m'
# ---------------------------------------------------
def highlight(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return '\033[;103m'+ s + '\033[0m'
# ---------------------------------------------------
def color_text(s, color):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    if color.lower() == "red":
        return red(s)
    elif color.lower() == "green":
        return green(s)
    elif color.lower() == "blue":
        return blue(s)
    else:
        return s
# ---------------------------------------------------
def color_tag(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    show = ""
    j = s.find("<red>")
    if j >= 0:
        k = s.find("</>")
        if k >= 0:
            show += red(s[j+5:k])
    j = s.find("<green>")
    if j >= 0:
        k = s.find("</>")
        if k >= 0:
            show += green(s[j+7:k])
    j = s.find("<blue>")
    if j >= 0:
        k = s.find("</>")
        if k >= 0:
            show += blue(s[j+6:k])
    return show
# ---------------------------------------------------
def highlight_words(s, words):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    for w in words:
        s = s.replace(w, highlight(w))
    return s
# ---------------------------------------------------
def display_tag_file(filename):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    fn = open(filename, 'r', encoding='utf-8')
    lines = fn.readlines()
    for line in lines:
        line = line.replace("<red>",'\033[;31m')
        line = line.replace("<green>",'\033[;32m')
        line = line.replace("<blue>",'\033[;34m')
        line = line.replace("</>",'\033[0m')
        print(line)
    fn.close()

6530112221: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_21.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display1.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 730, 'const': 591, 'code+const': 1321}
def red(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return (RED + s + RESET)
# ---------------------------------------------------
def green(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return (GREEN + s + RESET)
# ---------------------------------------------------
def blue(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return (BLUE + s + RESET)
# ---------------------------------------------------
def highlight(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return (HIGHLIGHT + s + RESET)
# ---------------------------------------------------
def color_text(s, color):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    if color.lower() == 'red':
        return red(s)
    elif color.lower() == 'green':
        return green(s)
    elif color.lower() == 'blue':
        return blue(s)
    return s
# ---------------------------------------------------
def color_tag(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    temp_1 = s.find('>')
    color = s[1:temp_1]
    temp_2 = s.find('</>', temp_1 + 1)
    return color_text(s[temp_1 + 1 : temp_2], color)
# ---------------------------------------------------
def highlight_words(s, words):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    pointer = 0
    highlighted = ''
    check = 0
    while pointer < len(s):
        for i in words:
            if s[pointer : pointer + len(i)].lower() == i.lower():
                highlighted += highlight(s[pointer : pointer + len(i)])
                pointer += len(i) - 1
                check = 1
        if check == 0:
            highlighted += s[pointer]
        pointer += 1
        check = 0
    return highlighted
# ---------------------------------------------------
def display_tag_file(filename):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    col_taglist = ['<red>', '<green>', '<blue>']
    colored_line = ''
    color = 0
    pointer = 0
    text = open(filename, 'r', encoding='utf-8')
    line = text.readline()
    while len(line) > 0:
        check = 0
        while pointer < len(line):
            for col in col_taglist:
                if col == line[pointer : pointer + len(col)]:
                    end = line.find('</>', pointer) + 3
                    if line.find('</>', pointer) == -1:
                        line = line[:-1]
                        line += '</>\n'
                        color = col
                    else:
                        colored_line += color_tag(line[pointer : end])                  
                        pointer = end
                    check = 1
            if check == 0:
                colored_line += line[pointer]
                pointer += 1
            check = 0
        line = text.readline()
        pointer = 0
        if color != 0:
            end = line.find('</>', pointer) + 3
            colored_line += color_tag(color + line[pointer : end])
            color = 0
            pointer = end
    text.close()
    print(colored_line)

6530113921: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_21.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display0.0
abcrrrpkk

defgggocr

xyzbbbabc

abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 562, 'const': 479, 'code+const': 1041}
def red(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return RED + s + RESET
# ---------------------------------------------------
def green(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return GREEN + s + RESET
# ---------------------------------------------------
def blue(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return BLUE + s + RESET
# ---------------------------------------------------
def highlight(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return HIGHLIGHT + s + RESET
# ---------------------------------------------------
def color_text(s, color):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    if color.upper() == 'RED':
      return red(s)
    elif color.upper() == 'GREEN':
      return green(s)
    elif color.upper() == 'BLUE':
      return blue(s)
    else:
      return s
# ---------------------------------------------------
def color_tag(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return color_text(s[s.find('>')+1:s.find('</>')],s[1:s.find('>')])
# ---------------------------------------------------
def highlight_words(s, words):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    n = s.upper()
    for i in words:
      j = 0
      while n.find(i.upper(),j) != -1:
        j = n.find(i.upper(),j)
        s = s[:j] + highlight(s[j:j+len(i)]) + s[j+len(i):]
        j += len(highlight(s[j:j+len(i)]))
        n = s.upper()
    return s
# ---------------------------------------------------
def display_tag_file(filename):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    f = open(filename, 'r', encoding='utf-8')
    s = '-'.join(f)
    j = 0
    while s.find('<',j) != -1:
      j = s.find('<',j)
      s = s[:j] + color_tag(s[j:s.find('</>')+3]) + s[s.find('</>')+3:]
    s = s.replace('-','\n')
    f.close()
    print(s)

6530114521: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display1.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 720, 'const': 1138, 'code+const': 1858}
def red(s):
    return '\033[;31m' + s + '\033[0m'
# ---------------------------------------------------
def green(s):
    return '\033[;32m' + s + '\033[0m'
# ---------------------------------------------------
def blue(s):
    return '\033[;34m' + s + '\033[0m'
# ---------------------------------------------------
def highlight(s):
    return '\033[;103m' + s + '\033[0m'
# ---------------------------------------------------
def color_text(s, color):
    colorlek = color.lower()
    if colorlek == 'red' :
        return '\033[;31m' + s + '\033[0m'
    elif colorlek == 'green' :
        return '\033[;32m' + s + '\033[0m'
    elif colorlek == 'blue' :
        return '\033[;34m' + s + '\033[0m'
    else :
        return s 
# ---------------------------------------------------
def color_tag(s):
    if s[:5:] == '<red>' and s[-3::-1] == '</>' :
        a = '\033[;31m' + s[5:-3:1] + '\033[0m'
        return a
    elif s[:7:] == '<green>' and s[-3::-1] == '</>' :
        a = '\033[;32m' + s[7:-3:1] + '\033[0m'
        return a
    elif s[:6:] == '<blue>' and s[-3::-1] == '</>' :
        a = '\033[;34m' + s[6:-3:1] + '\033[0m'
        return a
# ---------------------------------------------------
def highlight_words(s, words):
    for e in words :
        if e in s :
            s = s.split(e)
            s = ('\033[;103m' + e + '\033[0m').join(s)
    return s
# ---------------------------------------------------
def display_tag_file(filename):
    op = open(filename,'r', encoding='utf-8')
    result = ''
    for line in op :
        a = line.split('</>')
        for e in a :
            if '<red>' in e :
                e = e.replace(e[e.find('<red>'):], red(e[e.find('<red>')+len('<red>'):]))
                result += e
            elif '<blue>' in e :
                e = e.replace(e[e.find('<blue>'):], blue(e[e.find('<blue>')+len('<blue>'):]))
                result += e
            elif '<green>' in e :
                e = e.replace(e[e.find('<green>'):], green(e[e.find('<green>')+len('<green>'):]))
                result += e
            else :
                result += e
    op.close()
    print(result)

6530115121: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_21.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display0.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 746, 'const': 720, 'code+const': 1466}
def red(s):
    j=RED+s+RESET
    return j
# ---------------------------------------------------
def green(s):
    j=GREEN+s+RESET
    return j
# ---------------------------------------------------
def blue(s):
    j=BLUE+s+RESET
    return j
# ---------------------------------------------------
def highlight(s):
    j=HIGHLIGHT+s+RESET
    return j
# ---------------------------------------------------
def color_text(s, color):
    A=color.lower()
    if  A == "red":
        return red(s)
    elif  A == "green":
        return green(s)
    elif A == "blue":
        return blue(s)
    else:
        return s
# ---------------------------------------------------
def color_tag(s):
    a=s.find(">")
    b=s.find("</>")
    text = s[a+1:b:]
    A = s[1:a:]
    return color_text(text, A)
# ---------------------------------------------------
def highlight_words(s, words):
    I=[]
    SI=-1
    cw=0
    WORDS=[]
    Q=""
    for i in range (len(words)):#[]ตัวใหญ่หมด
        WORDS.append(words[i].upper())
    S=s.upper()#sตัวใหญ่หมด
    for i in range(len(WORDS)):
        cw=S.count(WORDS[i])
        for e in range(cw):
            if cw >0:
                SI=S.find(WORDS[i],SI+1)
                I.append([SI,SI+len(WORDS[i])])
        SI=-1
    I.sort()
    CHECK=0
    I.append(["หากว่าโลกนี้ไม่มีดวงจันทร์","จะบอกว่ารักทั้งจักรวาลมันก้ยังไม่พอ"])
    for i in range(len(s)):
        if i == I[CHECK][0]:
            Q+=HIGHLIGHT
            Q+=s[i]
        elif  i == I[CHECK][1]:
            Q+=RESET
            if i ==I[CHECK+1][0]:
                Q+=HIGHLIGHT
            Q+=s[i]
            CHECK+=1
        else:
            Q+=s[i]
    Q+=RESET
    return Q      
# ---------------------------------------------------
def display_tag_file(filename):
    fn= open(filename, 'r', encoding='utf-8')
    x=""
    for line in fn:
        x+=line
    A1=x.split("<red>")
    S1=RED.join(A1)
    A2=S1.split("<green>")
    S2=GREEN.join(A2)
    A3=S2.split("<blue>")
    S3=BLUE.join(A3)
    A4=S3.split("</>")
    S4=RESET.join(A4)
    fn.close()
    return S4

6530116821: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_10.0 return ans
^
IndentationError: unindent does not match any outer indentation level
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0 return ans
^
IndentationError: unindent does not match any outer indentation level
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display0.0 return ans
^
IndentationError: unindent does not match any outer indentation level
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {}
# HW4_String_File_Processing (ไม่ลบหรือแก้ไขบรรทัดนี้ หรือเพิ่มอะไรก่อนบรรทัดนี้ โดยเด็ดขาด)

# - เขียนในเซลล์นี้เท่านั้น 
# - ถ้าต้องการเขียนฟังก์ชันเพิ่ม ก็เขียนในเซลล์นี้

# ตัวแปรต่อไปนี้เป็นตัวแปรที่กำหนดค่าสีเพื่อเอาไว้ใช้ในโปรแกรม (ห้ามแก้ไข)
RESET = '\033[0m'
RED = '\033[;31m'
GREEN = '\033[;32m'
BLUE = '\033[;34m'
HIGHLIGHT = '\033[;103m'

# ---------------------------------------------------
def red(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return RED+s+RESET
# ---------------------------------------------------
def green(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return green+s+RESET
# ---------------------------------------------------
def blue(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return blue+s+RESET
# ---------------------------------------------------
def highlight(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return HIGHLIGHT+s+RESET
# ---------------------------------------------------
def color_text(s, color):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    if color.lower()=='red':
        return red(s)
    if color.lower()=='green':
        return green(s)
    if color.lower()=='blue':
        return blue(s)
    if color.lower()=='highlight':
        return highlight(s)
# ---------------------------------------------------
def color_tag(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    x=s.replace('<',',',2)
    y=x.replace('>',',',2)
    z=y.strip(',')
    a=z.split(',')
    return color_text(a[1],a[0])
# ---------------------------------------------------
def highlight_words(s, words):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    a=s.lower()
    y=[]
    t=s
    for i in words:
        k=i.lower()
        y.append(k)
    for i in y:
        for j in range(len(a)-len(i)+1):
            if a[j:j+len(i)]==i:
                x=highlight(t[j:j+len(i)])
                s=s.replace(t[j:j+len(i)],x)
    return s
# ---------------------------------------------------
def display_tag_file(filename):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    fn = open(filename, 'r', encoding='utf-8')
    str = fn.read()
    x = str.split("</>")
    ans = ""
    for i in x:
        if "<red>" in i:
            i = i.replace(i[i.find("<red>"):],color_tag(i[i.find("<red>"):]+"</>"))
            ans += i
        elif "<green>" in i:
            i = i.replace(i[i.find("<green>"):],color_tag(i[i.find("<green>"):]+"</>"))
            ans += i
        elif "<blue>" in i:
            i = i.replace(i[i.find("<blue>"):],color_tag(i[i.find("<blue>"):]+"</>"))
            ans += i
        else:
            ans += i
   return ans

6530117421: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_21.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display1.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 736, 'const': 593, 'code+const': 1329}
def red(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    r = RED; r += s; r += RESET
    return r
# ---------------------------------------------------
def green(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    r = GREEN; r += s; r += RESET
    return r
# ---------------------------------------------------
def blue(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    r = BLUE; r += s; r += RESET
    return r
# ---------------------------------------------------
def highlight(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    r = HIGHLIGHT; r += s; r += RESET
    return r
# ---------------------------------------------------
def color_text(s, color):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    s = str(s)
    color = color.strip().upper()
    if color == "RED": return red(s)
    elif color == "GREEN": return green(s)
    elif color == "BLUE": return blue(s)
    else: return s
# ---------------------------------------------------
def color_tag(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    x = s.find(">")
    n = s.find("</>",x)
    c = s[1:x]
    text = s[x+1:n]
    if c == "red": return red(text)
    elif c == "green": return green(text)
    elif c == "blue": return blue(text)
    else: pass
# ---------------------------------------------------
def highlight_words(s, words):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    ups = s.upper()
    rep = []
    for i in words:
      temp = i.upper()
      w = []
      ind = []
      st = 0
      while st != -1:
        st = ups.find(temp,st)
        if st == -1: break
        ind.append(st)
        st += len(temp)
      for j in ind:
        x = s[j:j+len(temp)]
        if x not in w: w.append(x)
      rep.append(w)
    for i in rep:
      for j in i:
        s = s.replace(j,highlight(j))
    return s
# ---------------------------------------------------
def display_tag_file(filename):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    text = ""
    infile = open(filename, 'r', encoding='utf-8')
    for line in infile:
      text += line
    text = text.replace("\n", "nxx")
    s = 0
    while s != -1:
      s = text.find("<",s)
      if s == -1: break
      n = text.find(">",s)
      n = text.find(">",n+1)
      text = text.replace(text[s:n+1], color_tag(text[s:n+1]))
    text = text.replace("nxx", "\n")
    print(text)
# ---------------------------------------------------

6530118021: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_21.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display0.0
abcrrrpkk

defgggocr

xyzbbbabc

abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 914, 'const': 609, 'code+const': 1523}
def red(s):
  word = RED+s+RESET
  return word
# ---------------------------------------------------
def green(s):
  word = GREEN+s+RESET
  return word
# ---------------------------------------------------
def blue(s):
  word = BLUE+s+RESET
  return word
# ---------------------------------------------------
def highlight(s):
  word = HIGHLIGHT+s+RESET
  return word
# ---------------------------------------------------
def color_text(s, color):
  color = color.lower()
  if color == "red" :
    word = red(s)
  elif color == "blue" :
    word = blue(s)
  elif color == "green" :
    word = green(s)
  else :
    word = s
  return word
# ---------------------------------------------------
def color_tag(s):
  i0 = s.find('<')
  i1 = s.find('>')
  i2 = s.find('<',i0+1)
  word = color_text(s[i1+1:i2],s[i0+1:i1])
  return word
# ---------------------------------------------------
def highlight_words(s, words):
  for e in words :
    if e.lower() in s.lower():
      l = s.lower().find(e.lower())
      while l != -1 :
        ed = l + len(e)
        s = s[:l] + ',' + s[l:ed] + ',' + s[ed:]
        l = s.lower().find(e.lower(),ed+1)
      sl = s.split(',')
      if sl[0].lower() == e.lower() :
        for i in range(0,len(sl),2):
          sl[i] = highlight(sl[i])
      else :
        for i in range(1,len(sl),2):
          sl[i] = highlight(sl[i])
      s = "".join(sl)
    else:
      s = s
  return s
# ---------------------------------------------------
def display_tag_file(filename):
  fn = open(filename, "r", encoding="utf-8")
  for line in fn :
    s = line.split("<")
    if "" in s: s.remove("")
    for i in range(len(s)) :
      if s[i][0] == "/" :
        s[i] = s[i][2::]
      elif s[i][0] == "r" and ">" in s[i] :
          l = s[i].find(">")
          s[i] = red(s[i][l+1::])
      elif s[i][0] == "b" and ">" in s[i] :
          l = s[i].find(">")
          s[i] = blue(s[i][l+1::])
      elif s[i][0] == "g" and ">" in s[i] :
          l = s[i].find(">")
          s[i] = green(s[i][l+1::])
    print("".join(s))
  fn.close()
# ---------------------------------------------------

6530119721: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display0.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 440, 'const': 715, 'code+const': 1155}
def red(s):
    return '\033[;31m'+s+'\033[0m'
# ---------------------------------------------------
def green(s):
    return '\033[;32m'+s+'\033[0m'
# ---------------------------------------------------
def blue(s):
    return '\033[;34m'+s+'\033[0m'
# ---------------------------------------------------
def highlight(s):
    return '\033[;103m'+s+'\033[0m'
# ---------------------------------------------------
def color_text(s,color):
    if color.lower()=='red':
        return red(s)
    elif color.lower()=='green':
        return green(s)
    elif color.lower()=='blue':
        return blue(s)
    else :
        return s
# ---------------------------------------------------
def color_tag(s):
    x = s.find("<")
    y = s.find("/")
    z = s.find(">")
    if s[x+1:z] == 'red':
        return '\033[;31m'+s[z+1:y-2]+'\033[0m'
    elif s[x+1:z] == 'green':
        return '\033[;32m'+s[z+1:y-2]+'\033[0m'
    elif s[x+1:z] == 'blue':
        return '\033[;34m'+s[z+1:y-2]+'\033[0m'
# ---------------------------------------------------
def highlight_words(s, words):
    for i in words:
        x = highlight(s[s.find(i):s.find(i)+len(i)])
        s = s.replace(i,x)
    return s
# ---------------------------------------------------
def display_tag_file(filename):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    pass

6530120221: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display1.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 668, 'const': 816, 'code+const': 1484}
def red(s):
  a = '\033[;31m' + s + '\033[0m'
  return a 
# ---------------------------------------------------
def green(s):
  b = '\033[;32m' + s + '\033[0m'
  return b 
# ---------------------------------------------------
def blue(s):
  c = '\033[;34m' + s + '\033[0m'
  return c
# ---------------------------------------------------
def highlight(s):
  d = '\033[;103m' + s + '\033[0m'
  return d 
# ---------------------------------------------------
def color_text(s, color):
  if color.upper() == "RED" :
    return red(s)
  if color.upper() == "GREEN" :
    return green(s)
  if color.upper() == "BLUE" :
    return blue(s)
  else:
    return s
# ---------------------------------------------------
def color_tag(s):
  if s[1]=='r' :
    return red(s[5:-3])
  if s[1]=='g' :
    return green(s[7:-3])
  if s[1]=='b' : 
    return blue(s[6:-3])
# ---------------------------------------------------
def highlight_words(s, words):
  for i in range(len(words)):
    s = s.replace(words[i], highlight(words[i]))
  return s
# ---------------------------------------------------
def display_tag_file(filename):
  data = open(filename, 'r', encoding='utf-8')
  new = ''
  for line in data:
    line_a = line.split('</>')
    for i in range(len(line_a)):
      if '<red>' in line_a[i] :
        line_b = line_a[i].split('<red>')
        new += line_b[0]
        if len(line_b) == 2 :
          line_b_red = red(line_b[1])
          new += line_b_red
      elif '<blue>' in line_a[i] :
        line_b = line_a[i].split('<blue>')
        new += line_b[0]
        if len(line_b) == 2 :
          line_b_blue = blue(line_b[1])
          new += line_b_blue
      elif '<green>' in line_a[i] :
        line_b = line_a[i].split('<green>')
        new += line_b[0]
        if len(line_b) == 2 :
          line_b_green = green(line_b[1])
          new += line_b_green
      else :
        new += line_a[i]
  data.close()
  return print(new)

6530121921: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_10.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display0.0UnboundLocalError("local variable 's' referenced before assignment")
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 706, 'const': 937, 'code+const': 1643}
def red(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    s = '\033[;31m' + s + '\033[0m'
    return(s)
# ---------------------------------------------------
def green(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    s = '\033[;32m' + s + '\033[0m'
    return(s)
# ---------------------------------------------------
def blue(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    s = '\033[;34m' + s + '\033[0m'
    return(s)
# ---------------------------------------------------
def highlight(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    s = '\033[103m' + s + '\033[0m'
    return(s)
# ---------------------------------------------------
def color_text(s, color):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    color = color.lower()
    if color == 'red':
        return(red(s))
    elif color == 'green':
        return(green(s))
    elif color == 'blue':
        return(blue(s))
    else:
      return(s)
# ---------------------------------------------------
def color_tag(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    if s.find("red") == 1:
        return red(s[5:-3:1])
    if s.find("green") == 1:
        return green(s[7:-3:1])
    if s.find("blue") == 1:
        return blue(s[6:-3:1])
# ---------------------------------------------------
def highlight_words(s, words):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    for i in range(len(words)):
        ans = ''
        p = 0
        a = s.lower() 
        while a.find(words[i].lower(),p) != -1:
            f = a.find(words[i].lower(),p) 
            ans += s[p:f:1] + highlight(s[f:f+len(words[i])]) 
            p = f + len(words[i]) 
        ans += s[p::] 
        s = ans
    return(s)
# ---------------------------------------------------
def display_tag_file(filename):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    file = open(filename, 'r', encoding='utf-8').read()
    words = ['red', 'green', 'blue']
    for w in words:
      w = '<' + w + '>'
      h = ''
      i = 0
      while (file.find(w, i) != -1):
        h+= file[i:file.find(w, i)]
        h+= str(color_tag(file[file.find(w, i):file.find('</>',i)+3]))
        i = (s.find(w,i) + len(file[file.find(w, i):file.find('</>',i)+3]))
      h += file[i:]
      s = h
    return(print(s))

6530123121: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0
['\x1b[;103mabcBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103maAbc\x1b[0mAbbcbf\x1b[;103mfgG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display0.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 570, 'const': 503, 'code+const': 1073}
def red(s):
    return RED+s+RESET
# ---------------------------------------------------
def green(s):
    return GREEN+s+RESET
# ---------------------------------------------------
def blue(s):
    return BLUE+s+RESET
# ---------------------------------------------------
def highlight(s):
    return HIGHLIGHT+s+RESET
# ---------------------------------------------------
def color_text(s, color):
    col = color.upper()
    if col == 'RED':
        return red(s)
    elif col == 'GREEN':
        return green(s)
    elif col == 'BLUE':
        return blue(s)
    else :
        return s
# ---------------------------------------------------
def color_tag(s):
    col1 = s.find('<')
    end = s.find('/')
    col2 = s.find('>')
    col = s[col1+1:col2]
    tex = s[col2+1:end-1]
    return color_text(tex,col)
# ---------------------------------------------------
def highlight_words(s, words):
    for w in words:
        tex = ''
        t = s.upper()
        n = 0
        W = w.upper()
        while t.find(W,n) != -1 :
            a = t.find(W,n)
            tex += s[n:a] + highlight(w)
            n = a + len(w)
        tex += s[n:len(s)]
        s = tex
    return s
# ---------------------------------------------------
def display_tag_file(filename):
    infile = open(filename, 'r', encoding='utf-8')
    text = ''
    s = ''
    for line in infile :
        text += line
    n = 0
    while text.find('<',n) != -1:
        col = text.find('<',n)
        end = text.find('/',n)
        color = color_tag(text[n:end+2])
        tex = text[n:col] + color
        n += len(tex)
        s += tex
    s += text[n:len(text)]
    return s

6530124821: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display1.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 540, 'const': 660, 'code+const': 1200}
def red(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    a = RED+str(s)+RESET
    return a
# ---------------------------------------------------
def green(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    a = GREEN+str(s)+RESET
    return a
# ---------------------------------------------------
def blue(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    a = BLUE+str(s)+RESET
    return a
# ---------------------------------------------------
def highlight(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    a = HIGHLIGHT+str(s)+RESET
    return a
# ---------------------------------------------------
def color_text(s, color):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    c = color.upper()
    a = ['BLACK', 'RED', 'GREEN', 'YELLOW', 'BLUE', 'MAGENTA', 'CYAN', 'WHITE']
    for i in range(len(a)):
      if c == str(a[i]):
        b = int(a.index(a[i]))+30
    code = '\033[;'+str(b)+'m'
    out = code+str(s)+RESET
    return out
# ---------------------------------------------------
def color_tag(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    s=s.replace('<red>',RED)    
    s=s.replace('<blue>',BLUE)
    s=s.replace('<green>',GREEN)
    s=s.replace('</>',RESET)
    return s
# ---------------------------------------------------
def highlight_words(s, words):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    if len(words) == 0:
      return s
    for i in range(len(words)):
      a = ''
      c = 0
      while s.find(words[i],c) != -1:
        a += s[c:s.find(words[i],c)] + highlight(words[i])
        c = s.find(words[i],c) + len(words[i])
      a += s[c::]
      s = a
    return s
def display_tag_file(filename):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    p = open(filename, 'r', encoding='utf-8')
    pans = ''
    for line in p:
      pans += color_tag(line)
    p.close()
    return print(pans)

6530125421: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_10.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display0.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 774, 'const': 464, 'code+const': 1238}
def red(s):
    return RED+s+RESET
# ---------------------------------------------------
def green(s):
    return GREEN+s+RESET
# ---------------------------------------------------
def blue(s):
    return BLUE+s+RESET
# ---------------------------------------------------
def highlight(s):
    return HIGHLIGHT+s+RESET
# ---------------------------------------------------
def color_text(s, color):
    c = color.upper()
    if c not in ['RED','GREEN','BLUE']:
        return s
    if c == 'RED':
        return red(s)
    if c == 'GREEN':
        return green(s)
    if c == 'BLUE':
        return blue(s)
# ---------------------------------------------------
def color_tag(s):
    sent = []
    val = 0
    if s.find('<',val) != 0:
        sent.append(s[0:s.find('<',val)])
    while s.find('<',val) != -1:
        opn = s.find('<',val)
        close = s.find('>',val)     
        color =  s[opn+1:close]
        endo = s.find('<',close+1)
        endc = s.find('>',close+1)
        val = endc+1
        c = color.upper()
        if c == 'RED':
            sent.append(red(s[close+1:endo]))
        elif c == 'GREEN':
            sent.append(green(s[close+1:endo]))
        elif c == 'BLUE':
            sent.append(blue(s[close+1:endo]))
        sent.append(s[endc+1:s.find('<',val)])
    if val != len(s):
        sent.append(s[-1::])
    text = "".join(sent)
    return text
# ---------------------------------------------------
def highlight_words(s, words):
    sent = []
    if len(words) == 0:
        return s
    for w in words:
        wlen = len(w)
        c = 0
        a = 0
        while s.find(w,c) != -1:
            sent.append(s[a:s.find(w,c)])
            sent.append(highlight(s[s.find(w,c):s.find(w,c) + wlen]))
            c = s.find(w,c) +1 + wlen
            a = c -1
        sent.append(s[c::]) 
        s = "".join(sent)
        sent = []
    return s
# ---------------------------------------------------
def display_tag_file(filename):
    f = open(filename)
    data = f.read()
    return color_tag(data)

6530126021: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_10.0
['\x1b[;103mabc\x1b[;0mde\x1b[;103mfg\x1b[;0m\x1b[;103mabc\x1b[;0mabbcbf\x1b[;103mfg\x1b[;0mcd\x1b[;103mabc\x1b[;0maa\x1b[;103mabc\x1b[;0m']
test_highlight_20.0
['\x1b[;103maBC\x1b[;0mde\x1b[;103mfg\x1b[;0m\x1b[;103mAbc\x1b[;0mAbbcbf\x1b[;103mfG\x1b[;0mcd\x1b[;103mabc\x1b[;0maa\x1b[;103mabc\x1b[;0m']
test_display0.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 804, 'const': 661, 'code+const': 1465}
def red(s):
    x = RED
    for c in s :
        x += c
    x += RESET
    return x
# ---------------------------------------------------
def green(s):
    x = GREEN
    for c in s :
        x += c
    x += RESET
    return x
# ---------------------------------------------------
def blue(s):
    x = BLUE
    for c in s :
        x += c
    x += RESET
    return x
# ---------------------------------------------------
def highlight(s):
    x = HIGHLIGHT
    for c in s :
        x += c
    x += RESET
    return x
# ---------------------------------------------------
def color_text(s, color):
    low =''
    for x in color:
        low += x.lower()
    if low =='red':
        z = red(s)
    elif low =='green':
        z = green(s)
    elif low =='blue':
        z = blue(s)
    else:
        z = s
    return z
# ---------------------------------------------------
def color_tag(s):
    x = s.split('</>')
    colorans= ''
    color = ''
    for i in range (len(x)) :
        fakeans= ''
        if '<red>' in x[i]:
            y = 5
            color= '<red>'
            z = red
        if '<blue>' in x[i]:
            y = 6
            color= '<blue>'
            z = blue
        if '<green>' in x[i]:
            y = 7
            color= '<green>'
            z = green
        fakeans += x[i]
        pos1 = fakeans.find(color)
        if pos1 == -1:
            for o in range(len(fakeans)):
                colorans += fakeans[o]
        else: 
            fakeans=fakeans.replace(color,'')
            for t in  range (0,pos1):
                colorans += fakeans[t]
            for o in range(pos1,len(fakeans)):
                colorans += z(fakeans[o])
    return colorans
# ---------------------------------------------------
def highlight_words(s, words):
    for i in words:
        q= ''
        x=0
        y = 0
        z = 0
        while x < len(s)+y:
            if s[z:z+len(i)].lower()==i.lower():
                q +='\033[;103m'+s[z:z+len(i)]+'\033[;0m'
                x = len(q)
                y += len('\033[;103m\033[;0m')
                z+=len(i)
            else:
                q+=s[z]
                z+=1
                x += 1
        s = q       
    return s
# ---------------------------------------------------
def display_tag_file(filename):
    text = open(filename, 'r', encoding='utf-8')
    text2 =''
    for line in text:
        text2 += line
    ans = color_tag(text2)
    text.close()
    return print(ans)

6530127721: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display1.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 380, 'const': 386, 'code+const': 766}
def red(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return RED+s+RESET
# ---------------------------------------------------
def green(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return GREEN + s + RESET
# ---------------------------------------------------
def blue(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return BLUE + s + RESET
# ---------------------------------------------------
def highlight(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return HIGHLIGHT + s + RESET
# ---------------------------------------------------
def color_text(s, color):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    if(color.lower()=="red"):
      return red(s)
    if(color.lower()=="green"):
      return green(s)
    if(color.lower()=="blue"):
      return blue(s)
    return s
# ---------------------------------------------------
def color_tag(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    ans = ""
    a = s.split("</>")
    for i in a:
      b = i.split(">")
      ans += b[0].split("<")[0]
      if(len(b) == 2):
        ans += color_text(b[1], b[0].split("<")[1])
    return ans
# ---------------------------------------------------
def highlight_words(s, words):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    for i in words:
      s = s.split(i)
      s = highlight(i).join(s)
    return s
# ---------------------------------------------------
def display_tag_file(filename):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    a = open(filename, 'r', encoding='utf-8').read()
    s = color_tag(a)
    print(s)
# print('red text:', red('red text'), 'and normal text')
# print('green text:', green('green text'), 'and normal text')
# print('blue text:', blue('blue text'), 'and normal text')
# print('highlight text:', highlight('highlight text'), 'and normal text')
# print("=========================")
# print(color_text('This is red text','red'))
# print(color_text('This is green text','GreeN'))
# print(color_text('This is blue text', 'BLUE'))
# print(color_text('This is yellow text', 'yellow'))
# print("=========================")
# print(color_tag('<red>red text</>'))
# print(color_tag('<green>green text</>'))
# print(color_tag('<blue>blue text</>'))
# print(color_tag("""<blue>blue text</>
# abcde----------------------------------------
# <red>red text
# test</><green>green text</>"""))
# print("=========================")
# t = 'a[3]มิใช่ลิสต์ คืนค่ามิใช่print =มิใช่เปรียบเทียบ รักมิใช่ดวงดาวที่พราวแสง'
# print(highlight_words(t,['มิใช่']))
# print(highlight_words(t,['ลิสต์']))
# print(highlight_words(t, []))
# w = ['print', 'ดาว', 'มิใช่']
# z = highlight_words(t, w)
# print(z)
# print("=========================")
# test ในเครื่องตัวเอง
# display_tag_file("มหาจุฬาลงกรณ์-tag.txt")

6530128321: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_10.0
['\x1b[;103m\x1b[0m\x1b\x1b[;103m\x1b[0m[\x1b[;103m\x1b[0m;\x1b[;103m\x1b[0m1\x1b[;103m\x1b[0m0\x1b[;103m\x1b[0m3\x1b[;103m\x1b[0mm\x1b[;103m\x1b[0ma\x1b[;103m\x1b[0mb\x1b[;103m\x1b[0mc\x1b[;103m\x1b[0m\x1b\x1b[;103m\x1b[0m[\x1b[;103m\x1b[0m0\x1b[;103m\x1b[0mm\x1b[;103m\x1b[0md\x1b[;103m\x1b[0me\x1b[;103m\x1b[0mf\x1b[;103m\x1b[0mg\x1b[;103m\x1b[0m\x1b\x1b[;103m\x1b[0m[\x1b[;103m\x1b[0m;\x1b[;103m\x1b[0m1\x1b[;103m\x1b[0m0\x1b[;103m\x1b[0m3\x1b[;103m\x1b[0mm\x1b[;103m\x1b[0ma\x1b[;103m\x1b[0mb\x1 ... (more)
test_highlight_20.0
['\x1b[;103m\x1b[0ma\x1b[;103m\x1b[0mB\x1b[;103m\x1b[0mC\x1b[;103m\x1b[0md\x1b[;103m\x1b[0me\x1b[;103m\x1b[0mf\x1b[;103mg\x1b[0mg\x1b[;103m\x1b[0mA\x1b[;103m\x1b[0mb\x1b[;103m\x1b[0mc\x1b[;103m\x1b[0mA\x1b[;103m\x1b[0mb\x1b[;103m\x1b[0mb\x1b[;103m\x1b[0mc\x1b[;103m\x1b[0mb\x1b[;103m\x1b[0mf\x1b[;103m\x1b[0mf\x1b[;103m\x1b[0mG\x1b[;103m\x1b[0mc\x1b[;103m\x1b[0md\x1b[;103m\x1b[0m\x1b\x1b[;103m\x1b[0m[\x1b[;103m\x1b[0m;\x1b[;103m\x1b[0m1\x1b[;103m\x1b[0m0\x1b[;103m\x1b[0m3\x1b[;103m\x1b[0mm\x1b[;10 ... (more)
test_display1.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 912, 'const': 618, 'code+const': 1530}
def red(s):
    return (RED + str(s) + RESET)
# ---------------------------------------------------
def green(s):
    return (GREEN + str(s) + RESET)
# ---------------------------------------------------
def blue(s):
    return (BLUE + str(s) + RESET)
# ---------------------------------------------------
def highlight(s):
    return (HIGHLIGHT + str(s) + RESET)
# ---------------------------------------------------
def color_text(s, color):
    newColor = color.lower()
    if (newColor == 'green'):
      return green(s)
    elif (newColor == 'blue'):
      return blue(s)
    elif (newColor == 'red'):
      return red(s)
    else:
      return s
# ---------------------------------------------------
def color_tag(s):
    result = ""
    sx = s
    while (sx.find('<red>') != -1 or sx.find('<blue>') != -1 or sx.find('<green>') != -1):
      t_rgb = ['<red>','<green>','<blue>']
      i_rgb = [sx.find('<red>'),sx.find('<green>'),sx.find('<blue>')]
      k = []
      for i in range(3):
        if (i_rgb[i] == -1):
          continue
        else:
          k.append([i_rgb[i],t_rgb[i]])
      k.sort()
      d = k[0]
      result += sx[0:d[0]]
      if (d[1]=='<red>'):
        result += red(sx[(d[0]+len(d[1])):sx.find('</>',d[0])])
      elif (d[1]=='<green>'):
        result+= green(sx[(d[0]+len(d[1])):sx.find('</>',d[0])])
      elif (d[1]=='<blue>'):
        result+= blue(sx[(d[0]+len(d[1])):sx.find('</>',d[0])])
      sx = sx[sx.find('</>',d[0])+3:]
    result = result + sx
    return result
# ---------------------------------------------------
def highlight_words(s, words):
    sx = s
    for i in words:
        if i.lower() in i.lower():
            sl = s.lower().find(i.lower())
            i = i[sl:sl+len(i)]
            sx = sx.replace(i, highlight(i))
    return sx
# ---------------------------------------------------
def display_tag_file(filename):
    result = ""
    ftxt = open(filename, 'r', encoding='utf-8')
    s = ""
    for i in ftxt:
        s += i
    s += " "*3
    j = 0
    while j <= len(s) - 3:
        if (s[j:j+3] != "<\n>") and (s[j] == "<"):
            result += color_tag(s[j:s.find("</>",j)+3])
            j = s.find("</>", j)+3
        else:
            result += s[j]
            j += 1
    ftxt.close()
    print(result)

6530129021: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_10.0NameError("name 'highlight_words' is not defined")
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0NameError("name 'highlight_words' is not defined")
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display0.0NameError("name 'display_tag_file' is not defined")
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 146, 'const': 127, 'code+const': 273}
def green(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return GREEN + s + RESET
# ---------------------------------------------------
def blue(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return BLUE + s + RESET
# ---------------------------------------------------
def highlight(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return HIGHLIGHT + s + RESET
# ---------------------------------------------------
def color_text(s, color):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    if color.lower() == 'red':
        return red(s)
    elif color.lower() == 'green':
        return green(s)
    elif color.lower() == 'blue':
        return blue(s)
    else:
        return s

6530130521: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display0.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 804, 'const': 956, 'code+const': 1760}
def red(s):
    txt = RED+'{words}'+RESET
    return txt.format(words = s)
# ---------------------------------------------------
def green(s):
    txt = GREEN+'{words}'+RESET
    return txt.format(words = s)
# ---------------------------------------------------
def blue(s):
    txt = BLUE+'{words}'+RESET
    return txt.format(words = s)
# ---------------------------------------------------
def highlight(s):
    txt = HIGHLIGHT+'{words}'+RESET
    return txt.format(words = s)
# ---------------------------------------------------
def color_text(s, color):
    if color.lower() == 'red':
        return red(s)
    elif color.lower() == 'green':
        return green(s)
    elif color.lower() == 'blue':
        return blue(s)
    else:
        return s
# ---------------------------------------------------
def color_tag(s):
    s_tag = s.find('>')
    e_tag = s.rfind('<')
    if s[1:s_tag] == 'red':
        return red(s[s_tag+1:e_tag])
    elif s[1:s_tag] == 'green':
        return green(s[s_tag+1:e_tag])
    elif s[1:s_tag] == 'blue':
        return blue(s[s_tag+1:e_tag])
# ---------------------------------------------------
def highlight_words(s, words):
    for i in words:
        s = s.replace(i, HIGHLIGHT+'{highlight_word}'+RESET)
        s = s.format(highlight_word = i)
    return s
# ---------------------------------------------------
def display_tag_file(filename):
    with open(filename, 'r', encoding='utf-8') as f:
        contents = f.read()
    s_tag_1 = 0
    while s_tag_1 != -1:
        s_tag_1 = contents.find('<')
        s_tag_2 = contents.find('>')
        e_tag = contents.find('</>')
        if s_tag_1 == -1:
            break
        if contents[s_tag_1+1:s_tag_2] == 'red':
            old_txt = contents[s_tag_1:e_tag+3]
            contents = contents.replace(old_txt, RED+'{txt}'+RESET)
            contents = contents.format(txt = old_txt[old_txt.find('>')+1:old_txt.find('</>')])
        elif contents[s_tag_1+1:s_tag_2] == 'green':
            old_txt = contents[s_tag_1:e_tag+3]
            contents = contents.replace(old_txt, GREEN+'{txt}'+RESET)
            contents = contents.format(txt = old_txt[old_txt.find('>')+1:old_txt.find('</>')])
        elif contents[s_tag_1+1:s_tag_2] == 'blue':
            old_txt = contents[s_tag_1:e_tag+3]
            contents = contents.replace(old_txt, BLUE+'{txt}'+RESET)
            contents = contents.format(txt = old_txt[old_txt.find('>')+1:old_txt.find('</>')])
    return contents

6530131121: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display1.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 660, 'const': 503, 'code+const': 1163}
def red(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return(RED+s+RESET)
# ---------------------------------------------------
def green(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return(GREEN+s+RESET)
# ---------------------------------------------------
def blue(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return(BLUE+s+RESET)
# ---------------------------------------------------
def highlight(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return(HIGHLIGHT+ s +RESET)
# ---------------------------------------------------
def color_text(s, color):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    color = color.lower()
    if color == "blue":
      result = blue(s)
    elif color == "red":
      result = red(s)
    elif color == "green":
      result = green(s)
    else:
      result=s
    return result
# ---------------------------------------------------
def color_tag(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    if "<blue>" in s or '<red>' in s or '<green>' in s:
      while '<blue>' in s:
        St = s.index("<blue>") + 6
        t = s[St:]
        En = t.index("</>") + 3 + St
        Sliced = s[St-6:En]
        New = s[St:En-3]
        New = color_text(New,"Blue")
        s = s.replace(Sliced,New)
      while '<green>' in s:
        St = s.index("<green>") + 7
        t = s[St:]
        En = t.index("</>") + 3 + St
        Sliced = s[St-7:En]
        New = s[St:En-3]
        New = color_text(New,"Green")
        s = s.replace(Sliced,New)
      while '<red>' in s:
        St = s.index("<red>") + 5
        t = s[St:]
        En = t.index("</>") + 3 +St
        Sliced = s[St-5:En]
        New = s[St:En-3]
        New = color_text(New,"Red")
        s = s.replace(Sliced,New)
    return s 
# ---------------------------------------------------
def highlight_words(s, words):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    for e in words: 
      s=s.replace(e,highlight(e))
    return s
# ---------------------------------------------------
def display_tag_file(filename):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
   F =  open(filename, 'r', encoding='utf-8')
   File = F.read()
   File = File.splitlines()
   for e in File:
     e = color_tag(e)
     print(e)
   F.close()

6530132821: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display0.0
abcrrrpkk

defgggocr

xyzbbbabc

abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 498, 'const': 499, 'code+const': 997}
def red(s):
    return RED + s + RESET
def green(s):
    return GREEN + s + RESET
def blue(s):
    return BLUE + s + RESET
def highlight(s):
    return HIGHLIGHT + s + RESET
def color_text(s, color):
    if color.lower() == "red":
        return red(s)
    elif color.lower() == "blue":
        return blue(s)
    elif color.lower() == "green":
        return green(s)
    elif color.lower() == "highlight":
        return highlight(s)
    else:
        return s
def is_color(s):
    return s == "red" or s == "blue" or s == "green"
def color_tag(s):
    lines = s.split("<")
    for i in range(len(lines)):
        splitted = lines[i].split(">")
        if len(splitted) != 1 and is_color(splitted[0]):
            lines[i] = color_text(splitted[1], splitted[0])
        elif splitted[0] == "/":
            lines[i] = splitted[1]
    return "".join(lines)
def highlight_words(s, words):
    text = s[:]
    for word in words:
        splited = text.split(word)
        text = highlight(word).join(splited)
    return text
def display_tag_file(filename):
    lines = []
    file = open(filename, "r", encoding="utf-8")
    for line in file:
        lines.append(color_tag(line))    
    for e in lines:
        print(e)

6530133421: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display0.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 706, 'const': 1150, 'code+const': 1856}
def red(s):
    return '\033[;31m'+s+'\033[0m' 
# ---------------------------------------------------
def green(s):
    return '\033[;32m'+s+'\033[0m' 
    pass
# ---------------------------------------------------
def blue(s):
    return '\033[;34m'+s+'\033[0m' 
    pass
# ---------------------------------------------------
def highlight(s):
    return '\033[;103m'+s+'\033[0m' 
    pass
# ---------------------------------------------------
def color_text(s, color):
    if color.lower() == 'red':
      return '\033[;31m'+s+'\033[0m'
    if color.lower() == 'green':
      return '\033[;32m'+s+'\033[0m'
    if color.lower() == 'blue':
      return '\033[;34m'+s+'\033[0m'
    return s
# ---------------------------------------------------
def color_tag(s):
      ans = ""
      st = s.find('<red>')
      if st != -1:
        fi = s.find('</>')
        ans += s[:st] + '\033[;31m' + s[st+5:fi]+'\033[0m' + s[fi+3:]
        return ans
      st = s.find('<green>')
      if st != -1:
        fi = s.find('</>')
        ans += s[:st] + '\033[;32m' + s[st+7:fi]+'\033[0m' + s[fi+3:]
        return ans
      st = s.find('<blue>')
      if st != -1:
        fi = s.find('</>')
        ans += s[:st] + '\033[;34m' + s[st+6:fi]+'\033[0m' + s[fi+3:]
        return ans
def highlight_words(s, words):
    for i in words:
        s = s.replace(i,'\033[;103m'+ i + '\033[0m')
    return s
def display_tag_file(filename) :
    file = open(filename, 'r', encoding='utf-8')
    ans = ""
    for i in file:
      if i.find("<") == -1:
        ans += i
      while i.find("<") != -1:
        start = i.find("<")
        stop_end = i.find("</>")
        x = i[start:stop_end+3]
        n1 = i[0:start]
        n2 = i[stop_end+3:]
        ans += n1+color_tag(x)
        i = n2
      if i in ans and i != "\n" :
        pass
      elif i.find("<") == -1:
        ans += i
    file.close()
    return ans

6530134021: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display1.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 414, 'const': 374, 'code+const': 788}
def red(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return RED+s+RESET
# ---------------------------------------------------
def green(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return GREEN+s+RESET
# ---------------------------------------------------
def blue(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return BLUE+s+RESET
# ---------------------------------------------------
def highlight(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return HIGHLIGHT+s+RESET
# ---------------------------------------------------
def color_text(s, color):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    color = color.lower()
    if color == 'red':
      return red(s)
    elif color == 'green':
      return green(s)
    elif color == 'blue':
      return blue(s)
    else:
      return s
# ---------------------------------------------------
def color_tag(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    w=s.replace('<red>',RED)
    x=w.replace('<green>',GREEN)
    y=x.replace('<blue>',BLUE)
    z=y.replace('</>',RESET)
    return z
# ---------------------------------------------------
def highlight_words(s, words):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    for e in words:
      x=s.find(e)
      while x!=-1:
        s=s[:x]+highlight(s[x:x+len(e)])+s[x+len(e):]
        x=s.find(e,x+len(highlight(e)))
    return s
# ---------------------------------------------------
def display_tag_file(filename):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    f=open(filename, 'r', encoding='utf-8')
    lines=f.readlines()
    for e in lines:
      print(color_tag(e).strip())

6530135721: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_21.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display1.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 768, 'const': 681, 'code+const': 1449}
def red(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return RED + s + RESET
# ---------------------------------------------------
def green(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return GREEN + s + RESET
# ---------------------------------------------------
def blue(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return BLUE + s + RESET
# ---------------------------------------------------
def highlight(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return HIGHLIGHT + s + RESET
# ---------------------------------------------------
def color_text(s, color):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    if color.upper() == 'RED':
      return RED + s + RESET
    elif color.upper() == 'GREEN':
      return GREEN + s + RESET
    elif color.upper() == 'BLUE':
      return BLUE + s + RESET
    else: return s
# ---------------------------------------------------
def color_tag(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    a = s.find('>')
    if s[1:a].upper() == 'RED':
      return RED + s[a+1:s.find('</>')] + RESET
    elif s[1:a].upper() == 'GREEN':
      return GREEN + s[a+1:s.find('</>')] + RESET
    elif s[1:a].upper() == 'BLUE':
      return BLUE +s[a+1:s.find('</>')] + RESET
    else: return s
# ---------------------------------------------------
def highlight_words(s, words):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    for w in words:
      w = w.upper()
      c = s.upper()
      i = 0
      h = ''
      while (c.find(w,i)!=-1):
        #print(s[i:s.find(w,i)],(HIGHLIGHT+s[s.find(w,i):s.find(w,i)+len(w)]+RESET),s.find(w,i),len(w))
        h+=s[i:c.find(w,i)]
        h+=(HIGHLIGHT+s[c.find(w,i):c.find(w,i)+len(w)]+RESET)
        i=(c.find(w,i)+len(w))
      h+=s[i:]
      c = h.upper()
      s = h
    return s
# ---------------------------------------------------
def display_tag_file(filename):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    s = open(filename, 'r', encoding='utf-8').read()
    words = ['red','green','blue']
    for w in words:
      w = '<' + w + '>'
      h=''
      i=0
      while (s.find(w,i)!=-1):
        h+=s[i:s.find(w,i)]
        #print(color_tag(s[s.find(w,i):s.find('</>',i)+3]))
        h+=str(color_tag(s[s.find(w,i):s.find('</>',i)+3]))
        i=(s.find(w,i)+len(s[s.find(w,i):s.find('</>',i)+3]))
      h+=s[i:]
      s = h
    print(s)
# ---------------------------------------------------

6530136321: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display0.0FileNotFoundError("No such file or directory: 'มหาจุฬาลงกรณ์-tag.txt'")
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 378, 'const': 494, 'code+const': 872}
def red(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return RED+s+RESET
# ---------------------------------------------------
def green(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return GREEN+s+RESET
# ---------------------------------------------------
def blue(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return BLUE+s+RESET
# ---------------------------------------------------
def highlight(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return HIGHLIGHT+s+RESET
# ---------------------------------------------------
def color_text(s, color):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    palette = ['red',red(s),'green',green(s),'blue',blue(s)]
    return palette[palette.index(color.lower())+1]
# ---------------------------------------------------
def color_tag(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    a = s[:-3].split('>')
    color,w = a[0][1:],a[1]
    return color_text(w,color)
# ---------------------------------------------------
def highlight_words(s, words):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    for w in words:
      s = s.replace(w,highlight(w))
    return s
# ---------------------------------------------------
def display_tag_file(filename):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    infile = open('มหาจุฬาลงกรณ์-tag.txt', 'r', encoding='utf-8')
    song = ''
    for line in infile:
      while '</>' in line:
        start = line.find('<')
        end = line.find('</>',start)
        w = str(line[start:end+3])
        line = line.replace(w,color_tag(w))
      song += line
    return song
    infile.close()

6530137021: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display0.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 356, 'const': 560, 'code+const': 916}
def red(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return ('\033[;31m'+s+'\033[0m')
# ---------------------------------------------------
def green(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return ('\033[;32m'+s+'\033[0m')
# ---------------------------------------------------
def blue(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return ('\033[;34m'+s+'\033[0m')
# ---------------------------------------------------
def highlight(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return ('\033[;103m'+s+'\033[0m')
# ---------------------------------------------------
def color_text(s, color):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    if color.lower() == 'red':
        return red(s)
    elif color.lower() == 'green':
        return green(s)
    elif color.lower() == 'blue':
        return blue(s)
    else:
        return s
# ---------------------------------------------------
def color_tag(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    if s[1] == 'r':
        return red(s[5:s.find('/')-1])
    elif s[1] == 'g':
        return green(s[7:s.find('/')-1])
    elif s[1] == 'b':
        return blue(s[6:s.find('/')-1])
def highlight_words(s, words):
    for i in words:
        s = s.replace(i,highlight(i))
    return s
# ---------------------------------------------------
def display_tag_file(filename):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    pass

6530138621: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display0.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 704, 'const': 946, 'code+const': 1650}
def red(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return '\033[;31m' + s + '\033[0m'
# ---------------------------------------------------
def green(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return '\033[;32m' + s + '\033[0m'
# ---------------------------------------------------
def blue(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return '\033[;34m' + s + '\033[0m'
# ---------------------------------------------------
def highlight(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return '\033[;103m' + s + '\033[0m'
# ---------------------------------------------------
def color_text(s, color):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    color = color.lower()
    if color == 'red':
        return red(s)
    elif color == 'green':
        return green(s)
    elif color == 'blue':
        return blue(s)
    else:
        return s
# ---------------------------------------------------
def color_tag(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    if s[-3:] == '</>':
        if s[:5] == '<red>':
            s = s[5:-3]
            l = color_text(s, 'red')
        elif s[:7] == '<green>':
            s = s[7:-3]
            l = color_text(s, 'green')
        elif s[:6] == '<blue>':
            s = s[6:-3]
            l = color_text(s, 'blue')
        return l
# ---------------------------------------------------
def highlight_words(s, words):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    for i in words:
        if i in s:
            s = s.split(i)
            s = highlight(i).join(s)
    return s
# ---------------------------------------------------
def display_tag_file(filename):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    x = open(filename, 'r', encoding='utf-8')
    V = ''
    for z in x:
        if z[-1] == '\n':
            line = z[:-1]
        else:
            line = z
        while line.find('<red>') != -1:
            J = line.find('<red>')
            K = line.find('</>', J)
            S = line[J:K + 3]
            F = color_tag(S)
            line = line.replace(S, F)
        while line.find('<green>') != -1:
            J = line.find('<green>')
            K = line.find('</>', J)
            S = line[J:K + 3]
            F = color_tag(S)
            line = line.replace(S, F)
        while line.find('<blue>') != -1:
            J = line.find('<blue>')
            K = line.find('</>', J)
            S = line[J:K + 3]
            F = color_tag(S)
            line = line.replace(S, F)
        V += line + '\n'
    x.close()
    return V[:-1]

6530139221: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display0.0FileNotFoundError("No such file or directory: 'มหาจุฬาลงกรณ์-tag.txt'")
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 944, 'const': 2459, 'code+const': 3403}
def red(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return RED + s + RESET # คืนผลลัพธ์เป็นสตริงที่ครอบด้วยรหัสสีและรหัส reset
# ---------------------------------------------------
def green(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return GREEN + s + RESET # คืนผลลัพธ์เป็นสตริงที่ครอบด้วยรหัสสีและรหัส reset
# ---------------------------------------------------
def blue(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return BLUE + s + RESET # คืนผลลัพธ์เป็นสตริงที่ครอบด้วยรหัสสีและรหัส reset
# ---------------------------------------------------
def highlight(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return HIGHLIGHT + s + RESET # คืนผลลัพธ์เป็นสตริงที่ครอบด้วยรหัสสีและรหัส reset
# ---------------------------------------------------
def color_text(s, color):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    color = color.upper() # แปลงชื่อสีให้เป็นตัวพิมพ์ใหญ่ จะได้ เช็กได้ง่าย
    if color == "RED": # ถ้า string color เป็นสีแดง
      return red(s) # คืนค่าเป็นสตริงที่แสดงผลเป็นสีตาม tag ที่ครอบข้อความไว้
    elif color == "GREEN": # ถ้า string color เป็นสีเขียว
      return green(s) # คืนค่าเป็นสตริงที่แสดงผลเป็นสีตาม tag ที่ครอบข้อความไว้
    elif color == "BLUE": # ถ้า string color เป็นสีน้ำเงิน
      return blue(s) # คืนค่าเป็นสตริงที่แสดงผลเป็นสีตาม tag ที่ครอบข้อความไว้
    else: # ถ้า string color ไม่เป็น 3 สี RED GREEN BLUE
      return s # คืนค่าเป็นสตริงที่ไม่เปลี่ยนแปลงอะไร
# ---------------------------------------------------
def color_tag(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    if '<red>' in s or '<green>' in s or '<blue>' in s: # ถ้ามี Tag <red>, <green>, <blue> ในข้อความ
      if '<red>' in s: # ถ้ามี Tag <red> ในข้อความ
        while '<red>' in s: # วนลูป while แปลงข้อความส่วนนั้น จนกว่าจะครบทุก Tag (ถ้าไม่เหลือ หรอไม่มี Tag แล้ว จะออกจากลูป while)
          START = s.index('<red>') # หา index เริ่มต้น ของ Tag เพื่อ Replace คำนั้นทั้งยวง โดยครอบด้วยรหัสสีแทน
          END = s.index('</>') # หา index สิ้นสุด ของ Tag เพื่อ Replace คำนั้นทั้งยวง โดยครอบด้วยรหัสสีแทน
          SliceReplace = s[START:END+3] # END+3 เพราะ ข้อความปิด Tag </> มี 3 ตัวอักษร
          SliceText = s[START+5:END] # START+ เพราะ ข้อความเปิด Tag <red> มี 5 ตัวอักษร
          NewText = color_text(SliceText , 'red') # แปลงข้อความ ครอบด้วยรหัสสีแทน Tag
          #print(SliceReplace)
          #print(SliceText)
          #print(NewText)
          s = s.replace(SliceReplace, NewText)
      if '<green>' in s: # ถ้ามี Tag <green> ในข้อความ
        while '<green>' in s: # วนลูป while แปลงข้อความส่วนนั้น จนกว่าจะครบทุก Tag (ถ้าไม่เหลือ หรอไม่มี Tag แล้ว จะออกจากลูป while)
          START = s.index('<green>')
          END = s.index('</>')
          SliceReplace = s[START:END+3]
          SliceText = s[START+7:END]
          NewText = color_text(SliceText , 'green')
          #print(SliceReplace)
          #print(SliceText)
          #print(NewText)
          s = s.replace(SliceReplace, NewText)
      if '<blue>' in s: # ถ้ามี Tag <blue> ในข้อความ
        while '<blue>' in s: # วนลูป while แปลงข้อความส่วนนั้น จนกว่าจะครบทุก Tag (ถ้าไม่เหลือ หรอไม่มี Tag แล้ว จะออกจากลูป while)
          START = s.index('<blue>')
          END = s.index('</>')
          SliceReplace = s[START:END+3]
          SliceText = s[START+6:END]
          NewText = color_text(SliceText , 'blue')
          #print(SliceReplace)
          #print(SliceText)
          #print(NewText)
          s = s.replace(SliceReplace, NewText)
    return s
# ---------------------------------------------------
def highlight_words(s, words):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    # highlight(s)
    STRING = "" # ลบออกได้ ตอนแรกใช้อีกวิธี ไม่มีผลต่อฟังก์ชั่น
    COUNT = 0 # ลบออกได้ ตอนแรกใช้อีกวิธี ไม่มีผลต่อฟังก์ชั่น
    for word in words: # วนลูปคำที่อยูาในลิสต์ทุกคำ
      #print(word)
      if word in s: # ถ้ามีคำนั้นในข้อความ
        s = s.replace(word, highlight(word)) # Replace คำนั้นด้วยคำใหม่ที่แปะครอบด้วยรหัส Hilight ข้อความ
    return s
# ---------------------------------------------------
def display_tag_file(filename):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    File = open('มหาจุฬาลงกรณ์-tag.txt', 'r', encoding='utf-8') # เปิดไฟล์อ่านข้อมูล
    STRING = File.read() # อ่านข้อมูลมาเก็บในตัวแปร STRING
    #print(STRING)
    LIST = STRING.splitlines() # Split แต่ละบรรทัดเก็บเป็นสมกชิกในลิสต์ LIST
    for i in LIST: # ดึงสมาชิกมาประมวลผลทีละตัว (ทีละบรรทัด)
      i = color_tag(i) # ประมวลผลสี
      print(i) # แสดงข้อความ
    File.close() # ปิดไฟล์
# ---------------------------------------------------
def test():
    # ตัวตรวจจะไม่สนใจการทำงานใดๆใน ฟังก์ชันนี้ นิสิตสามารถเพิ่มโค้ดในนี้เพื่อทดสอบฟังก์ชัน
    # ที่เขียนมาข้างบนได้
    # ตัวอย่างการเขียนโค้ดทดสอบฟังก์ชัน get_weighted_score
    display_tag_file("มหาจุฬาลงกรณ์-tag.txt")
    # Test 
    print('red text:', red('red text'), 'and normal text') #red text: red text and normal text
    print('green text:', green('green text'), 'and normal text') #green text: green text and normal text
    print('blue text:', blue('blue text'), 'and normal text') #blue text: blue text and normal text
    print('highlight text:', highlight('highlight text'), 'and normal text') #highlight text: highlight text and normal text
    # Test
    print(color_text('This is red text', 'red')) #This is red text
    print(color_text('This is green text', 'GreeN')) #This is green text
    print(color_text('This is blue text', 'BLUE')) #This is blue text
    print(color_text('This is yellow text', 'yellow')) #This is yellow text
    # Test
    print(color_tag('<red>red text</> red text <red>red text</>')) #red text
    print(color_tag('<green>green text</> <green>green text</> green text ')) #green text
    print(color_tag('blue text <blue>blue text</> <blue>blue text</> <blue>blue text</>')) #blue text
    print(color_tag('red text <red>red text</> green text <green>green text</> blue text <blue>blue text</>'))
    print(color_tag('red text <red>red text</> green text <green>green text</> blue text <blue>blue text</> red text <red>red text</> green text <green>green text</> blue text <blue>blue text</>')) #blue text
    print(color_tag('ขอ<red>องค์</>พระเอื้อ<blue>อาทร</> หลั่งพรคุ้มครอง'))
    print(color_tag('ถาวรยศอยู่คู่ไทย เชิดชัย ชโย'))
    # Test
    t = 'a[3]มิใช่ลิสต์ คืนค่ามิใช่print =มิใช่เปรียบเทียบ รักมิใช่ดวงดาวที่พราวแสง'
    print(highlight_words(t,['มิใช่'])) #a[3]มิใช่ลิสต์ คืนค่ามิใช่print =มิใช่เปรียบเทียบ รักมิใช่ดวงดาวที่พราวแสง`
    print(highlight_words(t,['ลิสต์'])) #a[3]มิใช่ลิสต์ คืนค่ามิใช่print =มิใช่เปรียบเทียบ รักมิใช่ดวงดาวที่พราวแสง
    print(highlight_words(t, [])) #a[3]มิใช่ลิสต์ คืนค่ามิใช่print =มิใช่เปรียบเทียบ รักมิใช่ดวงดาวที่พราวแสง
    w = ['print', 'ดาว', 'มิใช่']
    z = highlight_words(t, w)
    print(z)

6530140821: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display1.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 834, 'const': 803, 'code+const': 1637}
def red(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    s = RED+s+RESET
    return s
# ---------------------------------------------------
def green(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    s = GREEN+s+RESET
    return s
# ---------------------------------------------------
def blue(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    s = BLUE+s+RESET
    return s
# ---------------------------------------------------
def highlight(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    s = HIGHLIGHT+s+RESET
    return s
# ---------------------------------------------------
def color_text(s, color):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    if len(color)==3 and (color[0] in "Rr" and color[1] in "Ee" and color[2] in "Dd"):
        return RED+s+RESET
    elif len(color)==5 and (color[0] in "Gg" and color[1] in "Rr" and color[2] in "Ee" and color[3] in "Ee" and color[4] in "Nn"):
        return GREEN+s+RESET
    elif len(color)==4 and (color[0] in "Bb" and color[1] in "Ll" and color[2] in "Uu" and color[3] in "Ee"):
        return BLUE+s+RESET
    else:
        return s
# ---------------------------------------------------
def color_tag(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    if s[:5] == "<red>":
        return (RED+s[5:-3]+RESET)
    if s[:7] == "<green>":
        return (GREEN+s[7:-3]+RESET)
    if s[:6] == "<blue>":
        return (BLUE+s[6:-3]+RESET)
# ---------------------------------------------------
def highlight_words(s, words):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    for i in range(len(words)):
        s = s.replace(words[i],HIGHLIGHT+words[i]+RESET)
    return s
# ---------------------------------------------------
def display_tag_file(filename):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    file = open(filename, 'r', encoding='utf-8')
    t=""
    for line in file:
        line = str(line)
        while "<red>" in line:
            init = line.index("<red>")
            fini = line.index("</>",init)
            line = line[:init]+red(line[init+5:fini])+line[fini+3:]
        while "<green>" in line:
            init = line.index("<green>")
            fini = line.index("</>",init)
            line = line[:init]+green(line[init+7:fini])+line[fini+3:]
        while "<blue>" in line:
            init = line.index("<blue>")
            fini = line.index("</>",init)
            line = line[:init]+blue(line[init+6:fini])+line[fini+3:]
        t+=line
    print(t)
    file.close()

6530141421: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display0.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 552, 'const': 683, 'code+const': 1235}
def red(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return '\033[;31m' + s + '\033[0m'
# ---------------------------------------------------
def green(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return '\033[;32m' + s + '\033[0m'
# ---------------------------------------------------
def blue(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return '\033[;34m' + s + '\033[0m'
# ---------------------------------------------------
def highlight(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return '\033[;103m' + s + '\033[0m' 
# ---------------------------------------------------
def color_text(text, color):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    if color.lower() == "red": return red(text)
    elif color.lower() == "green": return green(text)
    elif color.lower() == "blue": return blue(text)
    else: return text
# ---------------------------------------------------
def color_tag(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    i = s.find(">")
    j = s.find("<",i)
    color = s[1:i]
    text = s[i+1:j]
    return color_text(text, color)
# ---------------------------------------------------
def highlight_words(s, words):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    text = s
    for e in words:
        i = s.find(e)
        while i != -1:
            h = highlight(s[i:len(e)+i])
            s = s[:i] + h + s[len(e)+i:]
            i = s.find(e,i+len(h))
    return s
# ---------------------------------------------------
def display_tag_file(filename):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    ans = ""
    infile = open(filename, 'r', encoding='utf-8')
    for line in infile:
        i = line.find("<")
        j = line.find("</>")
        while j != -1:
            colored = color_tag(line[i:j+3])
            line2 = line[j+3:]
            line1 = line[:i] + colored
            line = line1 + line2
            i = line.find("<",len(line1)+1)
            j = line.find("</>",len(line1)+1)
        ans += line
    return ans
# ---------------------------------------------------

6530142021: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0
['\x1b[;103mabcBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103maAbc\x1b[0mAbbcbf\x1b[;103mfgG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display0.0FileNotFoundError("No such file or directory: 'มหาจุฬาลงกรณ์-tag.txt'")
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 736, 'const': 738, 'code+const': 1474}
def red(s):
    return RED + s + RESET
# ---------------------------------------------------
def green(s): 
    return GREEN + s + RESET
# ---------------------------------------------------
def blue(s):
    return BLUE + s + RESET
# ---------------------------------------------------
def highlight(s):
    return HIGHLIGHT + s + RESET
# ---------------------------------------------------
def color_text(s, color):
   c = color.lower()
   if c == 'red':
     return red(s)
   elif c == 'green':
     return green(s)
   elif c == 'blue':
     return blue(s)
   else:
     return s
# ---------------------------------------------------
def color_tag(s):
    tagred = '<red>'
    taggreen = '<green>'
    tagblue = '<blue>'
    close = '</>'
    if s[0:len(tagred)] == tagred :
        txt = s[len(tagred):-len(close)]
        return color_text(txt,'red')
    elif s[0:len(taggreen)] == taggreen :
        txt = s[len(taggreen):-len(close)]
        return color_text(txt,'green')
    elif s[0:len(tagblue)] == tagblue :
        txt = s[len(tagblue):-len(close)]
        return color_text(txt,'blue')
# ---------------------------------------------------
def highlight_words(s, words):
  t = s
  for w in words :
    w = w.lower()
    x = []
    k0 = 0
    k = t.lower().find(w,0)
    while k >= 0 :
      x.append(t[k0:k])
      x.append(HIGHLIGHT + w + RESET)
      k0 = k+len(w)
      k = t.lower().find(w,k0)
    x.append(t[k0:])
    t = ''.join(x)
  return t
# ---------------------------------------------------
def display_tag_file(filename):
  fin = open('มหาจุฬาลงกรณ์-tag.txt', 'r', encoding='utf-8')
  t = fin.read()
  opns = ['<red>' ,'<green>', '<blue>']
  end = '</>'
  for opn in opns :
    x = []
    k0 = 0
    k = t.find(opn,0)
    while k >= 0 :
      x.append(t[k0:k])
      i = t.find(end,k)
      j = i+len(end)
      txt = t[k:j]
      modtxt = color_tag(txt)
      x.append(modtxt)
      k0 = j
      k = t.find(opn,k0)
    x.append(t[k0:])
    t = ''.join(x)
  print(t)
  fin.close()

6530143721: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_21.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display1.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 752, 'const': 513, 'code+const': 1265}
def red(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return RED + str(s) + RESET
# ---------------------------------------------------
def green(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return GREEN + str(s) + RESET
# ---------------------------------------------------
def blue(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return BLUE + str(s) + RESET
# ---------------------------------------------------
def highlight(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return HIGHLIGHT + str(s) + RESET
# ---------------------------------------------------
def color_text(s, color):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    if color.upper() == 'RED':
        return red(s)
    elif color.upper() == 'GREEN':
        return green(s)
    elif color.upper() == 'BLUE':
        return blue(s)
    else:
        return s
# ---------------------------------------------------
def color_tag(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    first_1 = s.find('<')
    last_1 = s.find('>')
    first_2 = s.find('<',first_1+1)
    color = s[first_1+1:last_1]
    text = s[last_1+1:first_2]
    if color.lower() == 'red':
        return red(text)
    elif color.lower() == 'green':
        return green(text)
    elif color.lower() == 'blue':
        return blue(text)
    else:
        return text
# ---------------------------------------------------
def highlight_words(s, words):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    #words = ['print', 'ดาว', 'มิใช่']
    words = [e.upper() for e in words] #words = ['PRINT', 'ดาว', 'มิใช่']
    t = s.upper() #a[3]มิใช่ลิสต์ คืนค่ามิใช่PRINT =มิใช่เปรียบเทียบ รักมิใช่ดวงดาวที่พราวแสง PRINT มิใช่ PRINT
    f = 0 ; l = 0
    for i in words:
        f = t.find(i) 
        l = f + len(i)
        char = s[f:l]
        while f != -1:
            s = s[:f] + highlight(char) + s[l:]
            t = s.upper()
            f = t.find(i,f+len(highlight(char)))
            l = f + len(i)
            char = s[f:l]
        f = 0 ; l = 0
    return s
    #สามารถ Highlight ทั้งตัวพิมพ์เล็ก - พิมพ์ใหญ่ได้
# ---------------------------------------------------
def display_tag_file(filename):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    fn = open(filename, "r", encoding = 'utf-8')
    st = ''
    for line in fn:
        st += line
    start = st.find('<')
    stop = st.find('<',start+1) + 3
    while start != -1:
        st = st[:start] + color_tag(st[start:stop]) + st[stop:]
        start = st.find('<',start+len(color_tag(st[start:stop])))
        stop = st.find('<',start+1) + 3
    print(st)
    fn.close()
    #สามารถอ่าน tag ข้ามบรรทัดได้

6530144321: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_21.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display1.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 768, 'const': 617, 'code+const': 1385}
def red(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return RED + s + RESET
# ---------------------------------------------------
def green(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return GREEN + s + RESET
# ---------------------------------------------------
def blue(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return BLUE + s + RESET
# ---------------------------------------------------
def highlight(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return HIGHLIGHT + s + RESET
# ---------------------------------------------------
def color_text(s, color):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    c = color.lower()
    if c == 'red': c = RED
    elif c == 'blue': c = BLUE
    elif c == 'green': c = GREEN
    else: c = ''
    return c + s + RESET
# ---------------------------------------------------
def color_tag(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    c = s[s.find('<')+1:s.find('>')]
    if c == 'red': c = RED
    elif c == 'blue': c = BLUE
    else : c = GREEN
    return c + s[s.find('>')+1:len(s)-3] + RESET
# ---------------------------------------------------
def highlight_words(s, words):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    t = ''; i = 0
    while i <= len(s) and len(words) != 0:
        mx = max([len(i) for i in words])
        ws = [i.lower() for i in words]
        try:
            for k in range(1,mx+1):
                w = s[i:i+k]
                if w.lower() in ws:
                    i += len(w); t += highlight(w); break
            else: t += s[i]; i += 1; w = ''
        except: break
    if len(words) == 0: return s
    else: return t
# ---------------------------------------------------
def display_tag_file(filename):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    f = open(filename, 'r', encoding='utf-8')
    l1 = [i.strip() for i in f]
    l2 = '|'.join(l1).split('</>')
    f.close()
    t = ''
    for i in l2:
        a = i.find('<'); b = i.find('>')
        if a == -1: t += i; break
        c = i[a+1: b]
        s = i[b+1:]
        t += i[:a] + color_text(s, c)
    [print(i) for i in t.split('|')]

6530145021: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display1.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 618, 'const': 519, 'code+const': 1137}
def red(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return RED+s+RESET
# ---------------------------------------------------
def green(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return GREEN+s+RESET
# ---------------------------------------------------
def blue(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return BLUE+s+RESET
# ---------------------------------------------------
def highlight(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return HIGHLIGHT+s+RESET
# ---------------------------------------------------
def color_text(s, color):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    color = color.lower()
    if color == 'red':
        return red(s)
    elif color == 'green':
        return green(s)
    elif color == 'blue':
        return blue(s)
    else:
        return s
# ---------------------------------------------------
def color_tag(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    t1 = s.find('>')
    t2 = s.find('/')
    color = s[1:t1]
    text = s[t1+1: t2-1]
    return color_text(text, color)
# ---------------------------------------------------
def highlight_words(s, words):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    for word in words:
        status_list = []
        # generating each case represented as binary for lower as 0 and upper as 1
        for i in range(2**len(word)):
            binary = i.__format__('b')
            while (len(binary) < len(word)):
                binary = '0'+binary
            status_list.append(binary)
        all_case_list = []
        # convert binary representation into all case of letters
        for status in status_list:
            temp = ''
            for i in range(len(status)):
                if status[i] == '0':
                    temp += word[i].lower()
                else:
                    temp += word[i].upper()
            all_case_list.append(temp)
        # check each case whether it's in s or not
        for case in all_case_list:
            if case in s:
                s = s.replace(case, highlight(case))
                break
    return s
# ---------------------------------------------------
def display_tag_file(filename):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    f = open(filename, 'r', encoding='utf-8')
    lis = [line for line in f]
    s = ''.join(lis)
    while '</>' in s:
        tag1 = s.find('<')
        tag2 = s.find('/')
        text = s[tag1: tag2 + 2]
        temp = color_tag(text)
        s = s.replace(text, temp)
    print(s)
    f.close()

6530146621: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display1.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 532, 'const': 529, 'code+const': 1061}
def red(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    y = RED + s + RESET
    return y
# ---------------------------------------------------
def green(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    y = GREEN + s + RESET
    return y
# ---------------------------------------------------
def blue(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    y = BLUE + s + RESET
    return y
# ---------------------------------------------------
def highlight(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    y = HIGHLIGHT + s + RESET
    return y
# ---------------------------------------------------
def color_text(s, color):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    a = color.upper()
    if a == 'RED':
        return red(s)
    elif a == 'GREEN':
        return green(s)
    elif a == 'BLUE':
        return blue(s)
    else:
        return s
# ---------------------------------------------------
def color_tag(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    a = ''
    for i in range(1,len(s)):
        if s[i] == '>':
            break
        a += s[i]
    b = ''
    for e in range(i+1,len(s)):
        if s[e] == '<':
            break
        b += s[e]
    return color_text(b,a)
# ---------------------------------------------------
def highlight_words(s, words):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    for i in words:
        s = s.replace(i,highlight(i))
    return s
# ---------------------------------------------------
def display_tag_file(filename):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    a = open(filename, 'r', encoding='utf-8')
    for i in a:
      if '</>' in i:
        for e in range(len(i)):
          if i[e] == '<' and i[e+1] != '/':
            x = ''
            y = 0
            while y < 2:
              if i[e] == '>':
                y += 1
              x += i[e]
              e += 1
            i = i.replace(x,color_tag(x))
      print(i, end = '')

6530147221: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display0.0NameError("name 'files' is not defined")
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 438, 'const': 439, 'code+const': 877}
def red(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    red = RED+s+RESET
    return red
# ---------------------------------------------------
def green(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    green = GREEN+s+RESET
    return green
# ---------------------------------------------------
def blue(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    blue = BLUE+s+RESET
    return BLUE
# ---------------------------------------------------
def highlight(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    highlight = HIGHLIGHT+s+RESET
    return HIGHLIGHT
# ---------------------------------------------------
def color_text(s, color):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    color = color.lower()
    if color == "red":
        x = RED+s+RESET
        return x
    elif color == "green":
        x = GREEN+s+RESET
        return x
    elif color == "blue":
        x = BLUE+s+RESET
        return x
    else:
        return s
# ---------------------------------------------------
def color_tag(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    y = s.split(">")
    y[1] = y[1].replace("</","")
    y[0] = y[0].replace("<","")
    if y[0] == "red":
        red = RED+y[1]+RESET
        return red
    elif y[0] == "green":
        green = GREEN+y[1]+RESET
        return green
    elif y[0] == "blue":
        blue = BLUE+y[1]+RESET
        return blue
    else:
        return s
# ---------------------------------------------------
def highlight_words(s, words):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    for i in range(len(words)):
        s = s.replace(words[i],'\033[;103m'+words[i]+'\033[0m')
    return s
# ---------------------------------------------------
def display_tag_file(filename):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    uploaded = files.upload(filename)

6530149521: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display1.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 528, 'const': 529, 'code+const': 1057}
def red(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return RED + s  + RESET
# ---------------------------------------------------
def green(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return  GREEN + s  + RESET
# ---------------------------------------------------
def blue(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return  BLUE + s  + RESET
# ---------------------------------------------------
def highlight(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return  HIGHLIGHT + s  + RESET
# ---------------------------------------------------
def color_text(s, color):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    if color.upper() == 'RED' :
      return red(s)
    elif color.upper() == 'GREEN' :
      return green(s)
    elif color.upper() == 'BLUE' :
      return blue(s)
    else :
      return s
# ---------------------------------------------------
def color_tag(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทนป
    c = ''
    for i in range (1,len(s)) :
      if s[i] == '>' :
        break 
      c += s[i]
    word = ''
    for j in range (i+1,len(s)):
      if s[j] == '<' :
        break
      word += s[j]
    return color_text(word,c)
# ---------------------------------------------------
def highlight_words(s, words):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    for x in words :
      s = s.replace(x,highlight(x))
    return s
# ---------------------------------------------------
def display_tag_file(filename):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    fout = open(filename, 'r', encoding='utf-8')
    for line in fout :
      if '</>' in line :
        for i in range(len(line)) :
          if line[i] == '<' and line[i+1] != '/' :
            c = ''
            count = 0 
            while count < 2 :
              if line[i] == '>' :
                count += 1 
              c += line[i]
              i +=1
            line = line.replace(c,color_tag(c))
      print(line , end = '')
    fout.close()

6530150021: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_10.0Time-out: 3s
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0Time-out: 3s
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display1.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 426, 'const': 388, 'code+const': 814}
def red(s):
    return RED + s + RESET
# ---------------------------------------------------
def green(s):
    return GREEN + s + RESET
# ---------------------------------------------------
def blue(s):
    return BLUE + s + RESET
# ---------------------------------------------------
def highlight(s):
    return HIGHLIGHT + s + RESET
# ---------------------------------------------------
def color_text(s, color):
    color = color.lower()
    if color == 'red':
      return red(s)
    if color == 'blue':
      return blue(s)
    if color == 'green':
      return green(s)
    return s
# ---------------------------------------------------
def color_tag(s):
    return s.replace('<red>', RED).replace('<blue>', BLUE).replace('<green>', GREEN).replace('</>', RESET)
# ---------------------------------------------------
def highlight_words(s, words):
    t = s.lower()
    for word in words:
      idx = t.find(word.lower())
      while idx != -1:
        s = s[:idx] + HIGHLIGHT + s[idx:idx+len(word)] + RESET + s[idx+len(word):]
        t = s.lower()
        idx = t.find(word.lower(), idx+len(word)+len(RESET)+1)
    return s
# ---------------------------------------------------
def display_tag_file(filename):
    f = open(filename, 'r', encoding='utf-8')
    lines = f.readlines()
    for line in lines:
      print(color_tag(line.strip()))

6530151721: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display0.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggogggrrzgggbbbabc
[]
bytecount: {'code': 736, 'const': 1058, 'code+const': 1794}
def red(s):
    d='\033[;31m'+s+'\033[0m'
    return d
# ---------------------------------------------------
def green(s):
    d='\033[;32m'+s+'\033[0m'
    return d
# ---------------------------------------------------
def blue(s):
    d='\033[;34m'+s+'\033[0m'
    return d
# ---------------------------------------------------
def highlight(s):
    d='\033[;103m'+s+'\033[0m'
    return d
# ---------------------------------------------------
def color_text(s, color):
    color=color.lower()
    if color=='red':
        d='\033[;31m'+s+'\033[0m'
        return d
    elif color=='green':
        d='\033[;32m'+s+'\033[0m'
        return d
    elif color=='blue':
        d='\033[;34m'+s+'\033[0m'
        return d
    else:return s
# ---------------------------------------------------
def color_tag(s):
    b=s.find('>')
    e=s.find('<')
    c=s.find('<',b)
    if s[e+1:b]=='red':
        d='\033[;31m'+s[b+1:c]+'\033[0m'
        return d
    elif s[e+1:b]=='green':
        d='\033[;32m'+s[b+1:c]+'\033[0m'
        return d
    elif s[e+1:b]=='blue':
        d='\033[;34m'+s[b+1:c]+'\033[0m'
        return d
    else:return s[b+1:c]
# ---------------------------------------------------
def highlight_words(s, words):
    for i in words:
        a=0
        c=1
        if i in s:
            while a!=-1:    
                a=s.find(i,a)
                s=s[:a]+highlight(s[a:a+len(i)])+s[a+len(i)::]
                a=s.find(i,a+7+len(i))
    return(s)   
# ---------------------------------------------------
def display_tag_file(filename):
    d=''
    file=open(filename, 'r', encoding='utf-8')
    for line in file:
        for i in ['red','blue','green']:
            a=0
            c=1
            if i in line:
                while a!=-1:    
                    a=line.find(i,a)-1
                    line=line[:a]+color_tag(line)+line[a+len(color_tag(line))-5+len(i)::]
                    a=line.find(i,a+7+len(i))
        d+=line        
    print(d)

6530152321: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display1.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 514, 'const': 1119, 'code+const': 1633}
def red(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return '\033[;31m'+s+'\033[0m'
# ---------------------------------------------------
def green(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return '\033[;32m'+s+'\033[0m'
# ---------------------------------------------------
def blue(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return '\033[;34m'+s+'\033[0m'
# ---------------------------------------------------
def highlight(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return '\033[;103m'+s+'\033[0m'
# ---------------------------------------------------
def color_text(s, color):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    x = color.lower()
    y = ['red','green','blue']
    z = ['\033[;31m','\033[;32m','\033[;34m']
    if x not in y:
      return s
    else:
      index = y.index(x)
      return z[index]+s+'\033[0m'
# ---------------------------------------------------
def color_tag(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    y = s.split('>')
    z = y[1].split('<')
    text = z[0]
    w = y[0].split('<')
    color = w[1]
    a = color.lower()
    b = ['red','green','blue']
    c = ['\033[;31m','\033[;32m','\033[;34m']
    index = b.index(a)
    return c[index]+text+'\033[0m'
# ---------------------------------------------------
def highlight_words(s, words):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    for i in words:
      x = '\033[;103m'+i+'\033[0m'
      s = s.replace(i,x)
    return s
# ---------------------------------------------------
def display_tag_file(filename):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    x = open(filename, 'r', encoding='utf-8')
    for line in x:
      for i in range(len(line)-1):
        a = ''
        c = 0
        if line[i] == '<' and line[i+1] != '/':
          for j in range (i,len(line)):
            if line[j] == '>':
              c += 1
            a += line[j]
            if c == 2:
              break
          line = line.replace(a,color_tag(a))  
      print(line,end='')

6530153021: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_10.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display1.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 502, 'const': 924, 'code+const': 1426}
def red(s):
    return '\033[31m{}\033[0m'.format(s)
# ---------------------------------------------------
def green(s):
    return '\033[32m{}\033[0m'.format(s)
# ---------------------------------------------------
def blue(s):
    return '\033[34m{}\033[0m'.format(s)
# ---------------------------------------------------
def highlight(s):
    return '\033[103m{}\033[0m'.format(s)
# ---------------------------------------------------
def color_text(s, color):
    if color.lower() == 'red':
        return red(s)
    elif color.lower() == 'green':
        return green(s)
    elif color.lower() == 'blue':
        return blue(s)
    else:
        return s
# ---------------------------------------------------
def color_tag(s):
    a = s.replace('</>',RESET)
    b = a.replace('<red>',RED)
    c = b.replace('<green>',GREEN)
    d = c.replace('<blue>',BLUE)
    return d
# ---------------------------------------------------
def highlight_words(s, words):
    for e in words:
        x = s.find(e)
        while x != -1:
            s = s[:x] + highlight(e) + s[x+len(e):]
            x = s.find(e,x+len(highlight(e)))
    return s 
# ---------------------------------------------------
def display_tag_file(filename):
    l = open(filename, 'r', encoding='utf-8')
    line = l.readlines()
    for e in line :
        print(color_tag(e.strip()))
def test():
    t = 'a[3]มิใช่ลิสต์ คืนค่ามิใช่print =มิใช่เปรียบเทียบ รักมิใช่ดวงดาวที่พราวแสง'
    print(highlight_words(t,['ลิสต์']))
    print(highlight_words(t, []))
    print(highlight_words(t,['มิใช่']))
    w = ['print', 'ดาว', 'มิใช่']
    z = highlight_words(t, w)
    print(z)
    print(color_tag('<red>red text</>'))

6530154621: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_21.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display0.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 844, 'const': 627, 'code+const': 1471}
def red(s):
    return RED+str(s)+RESET
# ---------------------------------------------------
def green(s):
    return GREEN+str(s)+RESET
# ---------------------------------------------------
def blue(s):
    return BLUE+str(s)+RESET
# ---------------------------------------------------
def highlight(s):
    return HIGHLIGHT+str(s)+RESET
# ---------------------------------------------------
def color_text(s,color):
    c=color.lower()
    if c=='red':
        return red(s)+RESET
    elif c=='blue' or c=='blu':
        return blue(s)+RESET
    elif c=='green' or c=='gre':
        return green(s)+RESET
    else:   
        return s
# ---------------------------------------------------
def color_tag(s):
    S=s.split('<')
    s1=S[-2][0:3];s2=S[-2]
    s2=s2.split('>')
    s3=s2[1]
    return color_text(s3,s1)
# ---------------------------------------------------
def highlight_words(s, words):
    if words!=[]:
        S=s.lower()
        m=""
        k=[]
        for p in words:
            l=len(p)
            for i in range(len(s)):
                if S[i:i+l]==p.lower():
                    k+=[[i,i+l]]
        k.sort()
        m+=s[0:k[0][0]]
        for n in range(len(k)-1):
            x=k[n][0];y=k[n][1]
            X=k[n+1][0]
            m+=highlight(s[x:y])+s[y:X]
        m+=highlight(s[k[-1][0]:k[-1][1]])+s[k[-1][1]:]
        return m
    else:
        return s
# ---------------------------------------------------
def display_tag_file(filename):
    f=open(filename, 'r', encoding='utf-8')
    line=f.readline()
    T=line;ans=''
    for line in f:
        T+=line
    T=T.split('<')
    for i in range(len(T)-1):
        if '>' in T[i] and T[i][0]!='/':
            temp=''
            temp='<'+T[i]+'<'+T[i+1]
            temp=color_tag(temp)
            ans+=temp
        elif T[i][0]=='/':
            ans+=T[i][2::]
        else:
            ans+=T[i]
    ans+=T[-1][2::]
    print(ans)

6530155221: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_10.0
[Non'\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0
[Non'\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display0.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 330, 'const': 580, 'code+const': 910}
def red(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    a = '\033[;31m'+s+'\033[0m'
    return(a)
# ---------------------------------------------------
def green(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    a = '\033[;32m'+s+'\033[0m'
    return(a)
# ---------------------------------------------------
def blue(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    a = '\033[;34m'+s+'\033[0m'
    return(a)
# ---------------------------------------------------
def highlight(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    a = '\033[;103m'+s+'\033[0m'
    return(a)
# ---------------------------------------------------
def color_text(s, color):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    color = color.lower()
    if color not in ['red','green','blue']:
      k = str(s)
    elif color == 'red':
      k = red(s)
    elif color == 'green':
      k = green(s)
    elif color == 'blue':
      k = blue(s)
    return(k)
# ---------------------------------------------------
def color_tag(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    if s[1] == 'r':
      a = red(s[5:-3])
    elif s[1] == 'g' :
      a = green(s[7:-3])
    elif s[1] == 'b' :
      a = blue(s[6:-3])
    return(a)
# ---------------------------------------------------
def highlight_words(s, words):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    #for i in range(len(words)):
      #if words[i] in t:
    pass
# ---------------------------------------------------
def display_tag_file(filename):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    pass

6530156921: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_21.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display1.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 752, 'const': 849, 'code+const': 1601}
def red(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    x='\033[;31m'+s+'\033[0m'
    return x
# ---------------------------------------------------
def green(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    x='\033[;32m'+s+'\033[0m'
    return x    
# ---------------------------------------------------
def blue(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    x='\033[;34m'+s+'\033[0m'
    return x    
# ---------------------------------------------------
def highlight(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    x='\033[;103m'+s+'\033[0m'
    return x    
# ---------------------------------------------------
def color_text(s, color):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    colour=color.lower()
    if colour =='red':
        changes=red(s)
        return changes
    elif colour =='green':
        changes=green(s)
        return changes
    elif colour =='blue':
        changes=blue(s)
        return changes
    else:
        return s
# ---------------------------------------------------
def color_tag(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    k=s[:-3]
    f1=k.find('<',0)
    f2=k.find('>',f1+1)
    see= k[f1+1:f2]
    n=s[1:-1]
    m1=n.find('>',0)
    m2=n.find('<',m1+1)
    senten= k[m1+2:m2+1]
    if see =='red':
        change=red(senten)
        return change
    elif see =='green':
        change=green(senten)
        return change
    elif see =='blue':
        change=blue(senten)
        return change
# ---------------------------------------------------
def highlight_words(s, words):
    s1 = s.upper()
    snew=''
    for kum in words:
        kum = kum.upper()
        f=s1.find(kum)
        while f!=-1:
            s=s[:f]+highlight(s[f:f+len(kum)])+s[f+len(kum):]
            s1=s1[:f]+highlight(kum)+s1[f+len(kum):]
            f=s1.find(kum,f+len(highlight(kum)))
    return s
# ---------------------------------------------------
def display_tag_file(filename):
    fn=open(filename,'r',encoding='utf-8')
    s=''
    for line in fn:
        s+=line
    h1=s.find('<')
    h2=s.find('/',h1+1)+2
    while h1!=-1:
        s=s[:h1]+color_tag(s[h1:h2])+s[h2:]
        h1=s.find('<')
        h2=(s.find('/',h1+1))+2
    print(s)
    fn.close()

6530157521: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display0.0ModuleNotFoundError("No module named 'pandas'")
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 490, 'const': 700, 'code+const': 1190}
def red(s):
    return '\033[;31m' + s + '\033[0m'   
# ---------------------------------------------------
def green(s):
    return '\033[;32m' + s + '\033[0m' 
# ---------------------------------------------------
def blue(s):
    return '\033[;34m' + s + '\033[0m' 
# ---------------------------------------------------
def highlight(s):
    return '\033[;103m' + s + '\033[0m' 
# ---------------------------------------------------
def color_text(s, color):
    color = color.lower()
    if color == 'red' :
      return red(s)
    elif color == 'blue' :
      return blue(s)
    else :
      return green(s)
# ---------------------------------------------------
def color_tag(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    a = s.split('<')
    c = a[1].split('>')
    if 'red' in c[0] :
      return red(c[1])
    elif 'green' in c[0] :
      return green(c[1])
    elif 'blue' in c[0] :
      return blue(c[1])
    else :
      return c[1] 
# ---------------------------------------------------
def highlight_words(s, words):
    for c in words:
        a=highlight(s[s.find(c):s.find(c)+len(c)])
        s=s.replace(c,a)
    return s
# ---------------------------------------------------
def display_tag_file(filename):
      import pandas as pd 
      df = pd.read_csv('มหาจุฬาลงกรณ์-tag.txt')
      df.head
      df.split('<')
      for i in len(df) :
        if df[i] == '/>' :
          pass
        else :
          df[i].replace(df[i] ,color_tag(str(df[i])))
      ().join(df)
      df.split('/>')
      ().join(df)
      return df

6530159821: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_21.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display1.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 892, 'const': 872, 'code+const': 1764}
def red(s):
    c=""
    c=RED+s+RESET
    return c
# ---------------------------------------------------
def green(s):
    c=""
    c=GREEN+s+RESET
    return c
# ---------------------------------------------------
def blue(s):
    c=""
    c=BLUE+s+RESET
    return c
# ---------------------------------------------------
def highlight(s):
    c=""
    c=HIGHLIGHT+s+RESET
    return c
# ---------------------------------------------------
def color_text(s, color):
    c=""
    color=color.strip().lower()
    if color=="red":
        c=RED+s+RESET
    elif color=="green":
        c=GREEN+s+RESET
    elif color=="blue":
        c=BLUE+s+RESET
    else:
        return s
    return c
# ---------------------------------------------------
def color_tag(s):
    s=s.strip()
    c=""
    g1=s.find("<")
    g2=s.find(">")
    s1=s.find("<",1)
    color=s[g1+1:g2]
    if color=="red":
        c=RED+s[g2+1:s1]+RESET
    elif color=="green":
        c=GREEN+s[g2+1:s1]+RESET
    elif color=="blue":
        c=BLUE+s[g2+1:s1]+RESET
    else:
        return s[g2+1:s1]
    return c
# ---------------------------------------------------
def highlight_words(s, words):
    ok=""
    if not words==[]:
        for check in words:
            new=""
            m=len(check)
            s=s+' '*m
            for i in range(len(s)):
                if s[i:i+m].upper()==check.upper():
                    new+="!^N=@="+s[i]
                else:
                    new+=s[i]
            k=new.split("!^N=@=")
            ans=""
            for i in k:
                if i[0:m].upper()==check.upper():
                    ans+=highlight(i[0:m])+i[m:]
                else:
                    ans+=i
            s=ans
        return ans
    else:
        return s
# ---------------------------------------------------
def display_tag_file(filename):
    s=open(filename, 'r', encoding='utf-8')
    save=""
    text=""
    for line in s:
        text+=line
    for i in text:
        c=0
        if i=="<":
            save+="!^N=@="+i
        else:
            save+=i
    k=save.split("!^N=@=")
    new=""
    for n in k:
        if n[0:3]=="</>":
            new+=n[3:]
        elif n[0:3]=="<re" or n[0:3]=="<bl" or n[0:3]=="<gr" :
            new+=color_tag(n+"</>")
        else:
            new+=n
    s.close()
    print(new)
# ---------------------------------------------------

6530160321: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display1.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 1162, 'const': 984, 'code+const': 2146}
def red(s):
    return (f'\033[;31m{s}\033[0m')
# ---------------------------------------------------
def green(s):
    return (f'\033[;32m{s}\033[0m')
# ---------------------------------------------------
def blue(s):
    return (f'\033[;34m{s}\033[0m')
# ---------------------------------------------------
def highlight(s):
    return (f'\033[;103m{s}\033[0m')
# ---------------------------------------------------
def color_text(s, color):
    color = color.lower()
    if color == "red" :
        x = red(s)
    elif color == "green" :
        x = green(s)
    elif color == "blue" :
        x = blue(s)
    else :
        x = s
    return x
# ---------------------------------------------------
def color_tag(s):
    x = ""
    for i in range(len(s)) :
        x += s[i]
        if x == "<red>" :
            break
        elif x == "<green>" :
            break
        elif x == "<blue>" :
            break
    k = s[len(x):][-1::-1][3:][-1::-1]
    if x == "<red>" :
        return red(k)
    elif x == "<green>" :
        return green(k)
    elif x == "<blue>" :
        return blue(k)     
# ---------------------------------------------------
def highlight_words(s, words):
    k = []
    x = ""
    for i in range(len(words)) :
        x = ""
        for e in range(len(s)) :
            x = x + s[e]
            if words[i] in x and e != len(s) - 1 :
                x = x.replace(words[i],highlight(words[i]))
                k.append(x)
                x = ""
            elif e == len(s) - 1 and words[i] in x :
                x = x.replace(words[i],highlight(words[i]))
                k.append(x)
                s = "".join(k)
                x = ""
                k = []
            elif e == len(s) - 1 and words[i] not in x :
                k.append(x)
                x = ""
                s = "".join(k)
                k = []
    return s
# ---------------------------------------------------
def display_tag_file(filename):
    f = open(filename, 'r', encoding='utf-8')
    x = []
    m = ""
    hotdog = []
    for line in f :
        x.append((line.strip()) + 'GG')
    f.close()
    x2 = "".join(x)
    x2 = x2 + "1.998"
    for i in range(len(x2)) :
        m = m + x2[i]
        if  (  "<red>" in m  ) and ("</>" in m[-3::1]) :
            in1 = m.find("<red>")
            t = m[in1+5:]
            m = m.replace("<red>" + t ,red(t))
            hotdog.append(m)
            m = ""
        elif  (  "<green>" in m  ) and ("</>" in m[-3::1]) :
            in1 = m.find("<green>")
            t = m[in1+7:]
            m = m.replace("<green>" + t ,green(t))
            hotdog.append(m)
            m = ""
        elif  (  "<blue>" in m  ) and ("</>" in m[-3::1]) :
            in1 = m.find("<blue>")
            t = m[in1+6:]
            m = m.replace("<blue>" + t ,blue(t))
            hotdog.append(m)
            m = ""
        elif "1.998" in m :
            hotdog.append(m[-1::-1][5:][-1::-1])       
    answer = "".join(hotdog)
    answer = answer.replace("</>","")
    answer = answer.replace("GG","\n")
    answer = answer[-1::-1][1:][-1::-1]
    print(  answer )

6530162621: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_10.0TypeError("\'type\' object is not subscriptable")
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0TypeError("\'type\' object is not subscriptable")
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display0.0TypeError("\'type\' object is not subscriptable")
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 478, 'const': 398, 'code+const': 876}
def red(s: str):
    return RED+s+RESET
# ---------------------------------------------------
def green(s: str):
    return GREEN+s+RESET
# ---------------------------------------------------
def blue(s: str):
    return BLUE+s+RESET
# ---------------------------------------------------
def highlight(s: str):
    return HIGHLIGHT+s+RESET
# ---------------------------------------------------
def color_text(s: str, c: str):
    if c.lower() == 'blue':
        return blue(s)
    elif c.lower() == 'red':
        return red(s)
    elif c.lower() == 'green':
        return green(s)
    else:
        return s
# ---------------------------------------------------
def color_tag(s: str):
    return s.replace('</>', RESET).replace('<red>', RED).replace('<green>', GREEN).replace('<blue>', BLUE)
# ---------------------------------------------------
def highlight_words(s: str, words: list[str]):
    for e in words:
        where = s.lower().find(e.lower())
        while where != -1:
            s = s[:where] + highlight(s[where:where+len(e)]) + s[where+len(e):]
            where = s.lower().find(e.lower(),where+len(highlight(s[where:where+len(e)])))
    return s
# ---------------------------------------------------
def display_tag_file(filename: str):
    with open(filename) as f:
        print(color_tag(f.read()))

6530163221: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display0.0MemoryError()
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 806, 'const': 744, 'code+const': 1550}
def red(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    ans = RED + s + RESET
    return ans
# ---------------------------------------------------
def green(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    ans = GREEN + s + RESET
    return ans
# ---------------------------------------------------
def blue(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    ans = BLUE + s + RESET
    return ans
# ---------------------------------------------------
def highlight(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    ans = HIGHLIGHT + s + RESET
    return ans
# ---------------------------------------------------
def color_text(s, color):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    if color.upper() == 'RED':
        return red(s)
    if color.upper() == 'GREEN':
        return green(s)
    if color.upper() == 'BLUE':
        return blue(s)
    if color.upper() == 'HIGHLIGHT':
        return highlight(s)
# ---------------------------------------------------
def color_tag(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    k = 0
    if s.find('<red>') != -1:
        return red(s[5:-3])
    if s.find('<blue>') != -1:
        return blue(s[6:-3])
    if s.find('<green>') != -1:
        return green(s[7:-3]) 
# ---------------------------------------------------
def highlight_words(s, words):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    ans = s
    k = 0
    for i in words:
        while ans.find(i,k) != -1:
            ans = ans[0:(ans.find(i,k))] + highlight(ans[(ans.find(i,k)):(ans.find(i,k)+len(i))]) + ans[(ans.find(i,k)+len(i)):]
            k = (ans.find(i,k)+len(i)) + 4
        k = 0
    return ans
# ---------------------------------------------------
def display_tag_file(filename):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    www = ''
    f = open(filename, 'r', encoding='utf-8')
    for line in f:
        while '<red>' in line:
            line = line[0:(line.find('<red>'))] + red(line[((line.find('<red>'))+5):line.find('</>')]) + line[(line.find('</>'))+3:]
        while '<blue>' in line:
            line = line[0:(line.find('<blue>'))] + blue(line[((line.find('<blue>'))+6):line.find('</>')]) + line[(line.find('</>'))+3:]
        while '<green>' in line:
            line = line[0:(line.find('<green>'))] + green(line[((line.find('<green>'))+7):line.find('</>')]) + line[(line.find('</>'))+3:]
        www = www + line + '\n'
    www = www[0:-1]
    return www
    f.close()

6530164921: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_10.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m\x1b[;103mfg\x1b[0m']
test_highlight_20.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m\x1b[;103mfg\x1b[0m']
test_display1.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 762, 'const': 978, 'code+const': 1740}
def red(s):
    result = ""
    result += "\033[;31m" + s + "\033[0m"
    return result
# ---------------------------------------------------
def green(s):
    result = ""
    result += "\033[;32m" + s + "\033[0m"
    return result
# ---------------------------------------------------
def blue(s):
    result = ""
    result += "\033[;34m" + s + "\033[0m"
    return result
# ---------------------------------------------------
def highlight(s):
    result = ""
    result += "\033[;103m" + s + "\033[0m"
    return result
# ---------------------------------------------------
def color_text(s, color):
    if color.lower() in "red":
        return red(s)
    elif color.lower() in "blue":
        return blue(s)
    elif color.lower() in "green":
        return green(s)
    else:
        return s
# ---------------------------------------------------
def color_tag(s):
    color = ""
    c = 0
    for i in s:
        if i == "<":
            c = 1
            continue
        elif i == ">":
            c = 0
            break
        if c==1:
            color += i
    st = ""
    for i in s:
        if i == ">":
            c = 1
            continue
        elif i == "/":
            c = 0
            break
        if c == 1:
            st += i
    st = st[:-1]
    if color == "red":
        return red(st)
    elif color == "green":
        return green(st)
    elif color == "blue":
        return blue(st)
# ---------------------------------------------------
def highlight_words(s, words):
    result = ""
    i = 0
    c = 0
    while i < len(s):
        for j in range(len(words)):
            if s[i:i+len(words[j]):] in words[j]:
                result += highlight(words[j])
                i += len(words[j])
                c = 1
        if c==1:
            c=0
        elif c==0:
            result += s[i]
            i+=1
    return result
# ---------------------------------------------------
def display_tag_file(filename):
    f = open(filename, 'r', encoding='utf-8')
    result = ""
    st = ""
    for line in f:
        for i in line:
            st += i
            if i == "/":
                for j in st:
                    if j == "<":
                        break
                    result += j
                result += color_tag(st+">")
                st = ""
                continue
            if st == ">":
                st = ""
                continue
        result += st + ""
        st = ""
    f.close()
    return print(result)

6530165521: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display1.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 686, 'const': 865, 'code+const': 1551}
def red(s):
    return f'\033[;31m{s}\033[0m'
# ---------------------------------------------------
def green(s):
    return f'\033[;32m{s}\033[0m'
# ---------------------------------------------------
def blue(s):
    return f'\033[;34m{s}\033[0m'
# ---------------------------------------------------
def highlight(s):
    return f'\033[;103m{s}\033[0m'
# ---------------------------------------------------
def color_text(s, color):
    color = color.lower()
    if color == 'red':
        return red(s)
    elif color == 'green':
        return green(s)
    elif color == 'blue':
        return blue(s)
    else:
        return s
# ---------------------------------------------------
def color_tag(s):
    keyword = s[s.find('<')+1 : s.find('>')]
    word = s[s.find('>')+1 : s.find('</>')]
    if keyword == 'red':
        return color_text(word, 'red')
    elif keyword == 'green':
        return color_text(word, 'green')
    elif keyword == 'blue':
        return color_text(word, 'blue')
# ---------------------------------------------------
def highlight_words(s, words):
    s = "win"+s
    for key in words :
        if key in s :
            k = s.split(key)
            s = highlight(key).join(k)
    return s[3:]
# ---------------------------------------------------
def display_tag_file(filename):
    a = ''
    file = open(filename, 'r', encoding='utf-8')
    infile = file.readlines()
    for line in infile:
        while '<red>' or '<green>' or '<blue>' in line:
            if '<red>' in line:
                key = line[line.find('<red>'):3+line.find('</>',line.find('<red>'))]
                ans = color_tag(key)
                new = line.split(key)
                line = ans.join(new)
            elif '<green>' in line:
                key = line[line.find('<green>'):3+line.find('</>',line.find('<green>'))]
                ans = color_tag(key)
                new = line.split(key)
                line = ans.join(new)
            elif '<blue>' in line:
                key = line[line.find('<blue>'):3+line.find('</>',line.find('<blue>'))]
                ans = color_tag(key)
                new = line.split(key)
                line = ans.join(new)
            else:
                a += line
                break
    print(a)
    file.close()

6530166121: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display1.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 478, 'const': 540, 'code+const': 1018}
def red(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return RED + s + RESET
# ---------------------------------------------------
def green(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return GREEN + s + RESET
# ---------------------------------------------------
def blue(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return BLUE + s + RESET
# ---------------------------------------------------
def highlight(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return HIGHLIGHT + s + RESET
# ---------------------------------------------------
def color_text(s, color):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    if color.lower() == 'red':
        return red(s)
    elif color.lower() == 'green':
        return green(s)
    elif color.lower() == 'blue':
        return blue(s)
    else:
        return s
# ---------------------------------------------------
def color_tag(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    i = s.find('<'); j = s.find('>'); k = s.find('<',1)
    color = s[i+1:j]
    if color.lower() == 'red':
        return red(s[j+1:k]) 
    elif color.lower() == 'green':
        return green(s[j+1:k]) 
    elif color.lower() == 'blue':
        return blue(s[j+1:k]) 
# ---------------------------------------------------
def highlight_words(s, words):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    for e in words:
        s = s.replace(e, highlight(e))
    return s
# ---------------------------------------------------
def display_tag_file(filename):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    fn = open(filename, 'r', encoding='utf-8')
    fin = ''
    for line in fn:
        line = line.replace('<red>', RED)
        line = line.replace('<blue>', BLUE)
        line = line.replace('<green>', GREEN)
        line = line.replace('</>', RESET)
        fin += line 
    print(fin)

6530167821: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display1.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 570, 'const': 528, 'code+const': 1098}
def red(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return RED+str(s)+RESET
# ---------------------------------------------------
def green(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return GREEN+str(s)+RESET
# ---------------------------------------------------
def blue(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return BLUE+str(s)+RESET
# ---------------------------------------------------
def highlight(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return HIGHLIGHT+str(s)+RESET
# ---------------------------------------------------
def color_text(s, color):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    x = ""
    if color == "red" :
        x+= RED+str(s)+RESET
    elif color == "blue" :
        x+= BLUE+str(s)+RESET
    elif color == "green" :
        x+= GREEN+str(s)+RESET
    else :
        x += str(s)
    return x
# ---------------------------------------------------
def color_tag(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    i = s.index(">")
    x = ""
    k = s[1:i]
    if k == "red" :
        x+= RED+s[i+1:-3]+RESET
    elif k == "blue" :
        x+= BLUE+s[i+1:-3]+RESET
    elif k == "green" :
        x+= GREEN+s[i+1:-3]+RESET
    else :
        x += str(s)
    return x
# ---------------------------------------------------
def highlight_words(s, words):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    y = s
    i = 0
    while i != len(words) :
        y=y.replace(words[i],HIGHLIGHT+words[i]+RESET)
        i+=1
    return y
# ---------------------------------------------------
def display_tag_file(filename):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    x = open(filename)
    y = ""
    for line in x :
        y+= line
        if "<red>" in y :
            y=y.replace("<red>",RED)
        if "<blue>" in  y:
                y=y.replace("<blue>",BLUE)
        if "<green>" in y :
                y=y.replace("<green>",GREEN)
        y=y.replace("</>",RESET)
    return print(y)

6530168421: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_21.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display1.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 572, 'const': 426, 'code+const': 998}
def red(s):
    return RED + s + RESET
# ---------------------------------------------------
def green(s):
    return GREEN + s + RESET
# ---------------------------------------------------
def blue(s):
    return BLUE + s + RESET
# ---------------------------------------------------
def highlight(s):
    return HIGHLIGHT + s + RESET
# ---------------------------------------------------
def color_text(s, color):
    col = color.lower()
    if col == 'red':
        out = red(s)
    elif col == 'green':
        out = green(s)
    elif col == 'blue':
        out = blue(s)
    else:
        out = s
    return out
# ---------------------------------------------------
def color_tag(s):
    start = s.find('>')
    stop = s.find('</>')
    h = s[start + 1:stop]
    c = s[1:start]
    return color_text(h, c)
# ---------------------------------------------------
def highlight_words(s, words):
    for e in words:
        x = 0
        n = s.lower().find(e.lower(),x)
        while n >= 0:
            high = s[0:n] + highlight(s[n:n + len(e)])
            out = high + s[n + len(e):]
            x = len(high)
            s = out
            n = s.lower().find(e.lower(),x)
    return s
# ---------------------------------------------------
def display_tag_file(filename):
    file = open(filename, 'r', encoding='utf-8')
    text = file.read()
    file.close()
    c = 0
    out = ''
    start = text.find('<', c)
    stop = text.find('</>', start)
    while start >= 0:
        out += text[c:start] + color_tag(text[start:stop + 3])
        c = stop + 3
        start = text.find('<', c)
        stop = text.find('</>', start)
    out += text[c:]
    print(out)

6530169021: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_21.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display1.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 564, 'const': 708, 'code+const': 1272}
def red(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return ('\033[;31m' + s + '\033[0m')
# ---------------------------------------------------
def green(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return ('\033[;32m' + s + '\033[0m')
# ---------------------------------------------------
def blue(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return ('\033[;34m' + s + '\033[0m')
# ---------------------------------------------------
def highlight(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return ('\033[;103m' + s + '\033[0m')
# ---------------------------------------------------
def color_text(s, color):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    if color.lower() == 'red':
        return red(s)
    elif color.lower() == 'green':
        return green(s)
    elif color.lower() == 'blue':
        return blue(s)
    return s
# ---------------------------------------------------
def color_tag(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    result = ''
    o = 0
    while s.find('</>',o) != -1:
        color = s[s.find('<',o)+1:s.find('>',o)]
        text = s[s.find('>',o)+1:s.find('</>',o)]
        result += s[o:s.find('<',o)] + color_text(text, color)
        o = s.find('</>',o)+3
    result += s[o:]
    return result
# ---------------------------------------------------
def highlight_words(s, words):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
     text = s
     for i in words:
        l = len(i)
        x = 0
        while True:
            if text.lower().find(i.lower(), x) != -1:
                j = text.lower().find(i.lower(), x)
                x = text.lower().find(i.lower(), x)+9
                text = text[:j] + highlight(text[j:j+l]) + text[j+l:]
            else:
                break
     return text
# ---------------------------------------------------
def display_tag_file(filename):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    text = ''
    file = open(filename, 'r', encoding='utf-8')
    for line in file :
        text += line
    print(color_tag(text))

6530170621: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display0.0
abcrrrpkk

defgggocr

xyzbbbabc

abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 658, 'const': 942, 'code+const': 1600}
def red(w):
    return '\033[;31m'+w+'\033[0m'
def green(w):
    return '\033[;32m'+w+'\033[0m'
def blue(w):
    return '\033[;34m'+w+'\033[0m'
def highlight(w):
    return '\033[;103m'+w+'\033[0m'
#----------------------------------------
def color_text(s,color):
    if color.lower() == 'red':
        return red(s)
    if color.lower() == 'green':
        return green(s)
    if color.lower() == 'blue':
        return blue(s)
    return s
#----------------------------------------
def color_tag(s):
    s=s.split('>')
    output=''
    for word in s:
        if len(word)==0:
            break
        if word.strip()[0] == '<':
            if word[0]==' ':
                output+=' '
            if word.strip()[1:] == 'red':
                output+='\033[;31m'
            if word.strip()[1:] == 'green':
                output+='\033[;32m'
            if word.strip()[1:] == 'blue':
                output+='\033[;34m'
        else:
            output+=word[:-2]+'\033[0m'
    return output
#----------------------------------------
def highlight_words(s,words):
    for e in words:
        k = s.find(e)
        a=k+len(e)
        while k!=-1:
            s=s[0:k]+highlight(e)+s[a:]
            k=s.find(e,k+len(highlight(e)))
            a=k+len(e)
    return s
# ---------------------------------------------------
def display_tag_file(filename):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    fn = open(filename, "r", encoding = 'utf-8')
    for line in fn:
        c=0
        for e in range(len(line)):
          if line[e] =='<':
            c+=0.5
        for i in range(int(c)):
          start = line.find('<')
          stop = line.find('<',start+1) + 3
          st = line[start:stop]
          line = line.replace(st, color_tag(st))
        print(line)
    fn.close()

6530171221: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_21.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display0.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 1030, 'const': 855, 'code+const': 1885}
def red(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return '\033[;31m'+s+'\033[0m'
# ---------------------------------------------------
def green(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return '\033[;32m'+s+'\033[0m'
# ---------------------------------------------------
def blue(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return '\033[;34m'+s+'\033[0m'
# ---------------------------------------------------
def highlight(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return '\033[;103m'+s+'\033[0m'
# ---------------------------------------------------
def color_text(s, color):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    a = color.lower()
    if a == "red" : return red(s)
    elif a == "blue" : return blue(s)
    elif a == "green" : return green(s)
    else : return s
# ---------------------------------------------------
def color_tag(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    final =  ''
    if s.find('</>') != -1 :
        n = 0
        for j in range(s.count('</>')):
            i = s.find('<',n)
            j = s.find('>',n)
            color = s[i+1:j]
            i2 = s.find('>',j)
            j2 = s.find('</>',n)
            n = j2+3
            txt = s[i2+1:j2]
            final += color_text(txt,color)
    return final
# ---------------------------------------------------
def highlight_words(s, words):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    index_s = []
    final = ''
    compare = s.lower()
    n = 0
    for i in words :
        if compare.find(i.lower()) != -1 :
            for e in range(len(s)):
                if [compare.find(i.lower(),e),len(i)] not in index_s and (compare.find(i.lower(),e) != -1):
                    index_s.append([compare.find(i.lower(),e),len(i)])         #หาตำแหน่งของคำที่ต้องการ
    index_s.sort()
    for i in range(len(index_s)) :
        final += s[n:index_s[i][0]]+highlight(s[index_s[i][0]:index_s[i][0]+index_s[i][1]])
        n = 0
        n += index_s[i][0]+index_s[i][1]
    final += s[n:]
    return final
# ---------------------------------------------------
def display_tag_file(filename):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    op = open(filename, "r", encoding="utf-8")
    line = []
    cl = []
    wc = ''
    wcl = []
    fin = ''
    for s in op :
        n = 0
        for k in range(s.count('</>')):
            j2 = s.find('</>',n)
            if s.count('</>')-k == 1:
                line.append(s[n:])
            else:
                line.append(s[n:j2+3])
            n = j2+3
        if not '</>' in s :
            line.append(s)
    for t in range(len(line)) :
        cl.append(color_tag(line[t]))
        n = 0
        wc = ''
        for k in range(line[t].count('</>')):
            i = line[t].find('<',n)
            j = line[t].find('>',n)
            i2 = line[t].find('>',j)
            j2 = line[t].find('</>',n)
            n = j2+3
            wc += line[t][i:j2+3]
        wcl += [wc]
    for j in range(len(wcl)):
        fin += line[j].replace(wcl[j],cl[j])
    return fin

6530172921: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display0.0
abcrrrpkk

defgggocr

xyzbbbabc

abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 598, 'const': 610, 'code+const': 1208}
def red(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return RED+s+RESET
# ---------------------------------------------------
def green(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return GREEN+s+RESET
# ---------------------------------------------------
def blue(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return BLUE+s+RESET
# ---------------------------------------------------
def highlight(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return HIGHLIGHT+s+RESET
# ---------------------------------------------------
def color_text(s, color):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    operator = color.lower()
    if operator == 'red':
      return red(s)
    elif operator == 'green':
      return green(s)
    elif operator == 'blue':
      return blue(s)
    else:
      return s
# ---------------------------------------------------
def color_tag(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    i = s.find('<')
    k = s.find('>')
    operator = s[i+1:k]
    e = s.find('</>')
    text = s[k+1:e].strip()
    return color_text(text, operator)
# ---------------------------------------------------
def highlight_words(s, words):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    for e in words:
      s_ref = s.lower()
      c = s_ref.find(e.lower())
      inter_text = s[c:c+len(e)]
      s = s.replace(inter_text,highlight(inter_text))
    return s
# ---------------------------------------------------
def display_tag_file(filename):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    color = ['red','green','blue']
    info = open(filename,'r',encoding='utf-8')
    for line in info:
      e = 0
      c = 0
      while e != -1:
        i = line.find('<',c)
        k = line.find('>',c)
        op = line[i+1:k]
        e = line.find('</>')
        if e == 0:
          line = line.replace('</>','')
          if line.strip() == '':
            line = line.strip()
        if op in color:
          if e == -1:
            line += '</>\n'
            e = line.find('</>')
          text_with_tag = line[i:e+3]
          line = line.replace(text_with_tag, color_tag(text_with_tag))
        else:
          c +=1
      if len(line) != 0:
        print(line)
    info.close()

6530173521: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display1.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 642, 'const': 949, 'code+const': 1591}
def red(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    a = '\033[;31m'+str(s)+'\033[0m'
    return a
# ---------------------------------------------------
def green(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    b = '\033[;32m'+str(s)+'\033[0m'
    return b
# ---------------------------------------------------
def blue(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    c = '\033[;34m'+str(s)+'\033[0m'
    return c
# ---------------------------------------------------
def highlight(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    d = '\033[;103m'+str(s)+'\033[0m'
    return d
# ---------------------------------------------------
def color_text(s, color):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    universe = ['RED','GREEN','BLUE']
    universe1 = [RED,GREEN,BLUE]
    j = 'j'
    if color.upper() in universe:
        k = universe.index(str(color.upper()))
        string = universe1[k] + s + RESET
        out1 = j.replace('j',string)
        return out1
    else:
        return s
# ---------------------------------------------------
def color_tag(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    tcolor = ''
    tempstr = ''
    universe = ['RED','GREEN','BLUE']
    universe1 = [RED,GREEN,BLUE]
    e = 1
    while s[e] != '>':
        tcolor += s[e]
        e += 1
    e += 1
    while s[e] != '<':
        tempstr += s[e]
        e += 1
    k = universe.index(str(tcolor.upper()))
    out2 = universe1[k] + tempstr + '\033[0m'
    return out2
# ---------------------------------------------------
def highlight_words(s, words):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    out3 = s
    for f in words:
        out3 = out3.split(f)
        hlword = highlight(f)
        out3 = hlword.join(out3) 
    return out3
# ---------------------------------------------------
def display_tag_file(filename):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    universe = ['RED','GREEN','BLUE']
    universe1 = [RED,GREEN,BLUE]
    text = open(filename, 'r', encoding='utf-8').readlines()
    text = ''.join(text)
    for i in range(len(text)+1):
        if text[i] == '<':
            e = i
            if text[i+1] != '/':
                while text[e] != '>':
                    e += 1
                m = text[i+1:e].upper()
                count = universe.index(m)
                text = text.replace(text[i:e+1],universe1[count])
            else:
              text = text.replace('</>',RESET)
    return print(text)

6530174121: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display1.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 802, 'const': 882, 'code+const': 1684}
def red(s):
    return '\033[;31m' + s + '\033[0m'
# ---------------------------------------------------
def green(s):
    return '\033[;32m' + s + '\033[0m'
# ---------------------------------------------------
def blue(s):
    return '\033[;34m' + s + '\033[0m'
# ---------------------------------------------------
def highlight(s):
    return '\033[;103m' + s + '\033[0m'
# ---------------------------------------------------
def color_text(s, color):
    if color.lower() == "red":
        return red(s)
    elif color.lower() == "green":
        return green(s)
    elif color.lower() == "blue":
        return blue(s)
    else:
        return s
# ---------------------------------------------------
def color_tag(s):
    if s.find("<red>") == 0:
        return red(s[5:-3:])
    elif s.find("<green>") == 0:
        return green(s[7:-3:])
    elif s.find("<blue>") == 0:
        return blue(s[6:-3:])
# ---------------------------------------------------
def highlight_words(s, words):
    if len(words) == 0:
            return s
    else:
        result = s
        for e in words:
            str = result.split(e)
            result = ""
            for i in range(len(str)):
                if i == 0:
                    result += str[i]
                elif i == len(str)-1:
                    if s[::-1].find(e[::-1]) == 0:
                        result += str[i] + highlight(e)
                    else:
                        result += highlight(e) + str[i]
                else:
                    result += highlight(e) + str[i]
    return result
# ---------------------------------------------------
def display_tag_file(filename):
    result = ""
    color = ["<red>","<green>","<blue>"]
    color_count = 0
    file = open(filename, 'r', encoding='utf-8')
    line = file.readline()
    while line:
        line_split = line.split("</>")
        for e in line_split:
            if e.find("<red>") != -1:
                result += e[0:e.find("<red>")] + color_tag(e[e.find("<red>"):]+"</>")
            elif e.find("<green>") != -1:
                result += e[0:e.find("<green>")] + color_tag(e[e.find("<green>"):]+"</>")
            elif e.find("<blue>") != -1:
                result += e[0:e.find("<blue>")] + color_tag(e[e.find("<blue>"):]+"</>")
            else:
                result += e
        line = file.readline()
    file.close()
    print(result)

6530176421: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display0.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 728, 'const': 775, 'code+const': 1503}
def red(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return RED+s+RESET
# ---------------------------------------------------
def green(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return GREEN+s+RESET
# ---------------------------------------------------
def blue(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return BLUE+s+RESET
# ---------------------------------------------------
def highlight(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return HIGHLIGHT+s+RESET
# ---------------------------------------------------
def color_text(s, color):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    c=''
    if color[0] in 'rR':
        for i in range(len(color)) :        
            if color[i] in 'rR':  
                c+='R'
            if color[i] in 'eE':
                c+='E'
            if color[i] in 'dD':
                c+='D'
            if c=='RED':
                return red(s)
    if color[0] in 'gG':
        for i in range(len(color)) :
            if color[i] in 'gG':
                c+='G'
            if color[i] in 'rR':
                c+='R'
            if color[i] in 'eE':
                c+='E'
            if color[i] in 'nN':
                c+='N'
            if c=='GREEN':
                return green(s)
    if color[0] in 'bB':
        for i in range(len(color)) :
            if color[i] in 'bB':
                c+='B'
            if color[i] in 'lL':
                c+='L'
            if color[i] in 'uU':
                c+='U'
            if color[i] in 'eE':
                c+='E'
            if c=='BLUE':
                return blue(s)
    else:
        return s
# ---------------------------------------------------
def color_tag(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    a1=s.find('<')
    a2=s.find('>')
    a3=s.find('<',a2+1)
    if s[a1+1:a2:]=='red':
        return red(s[a2+1:a3:])
    if s[a1+1:a2:]=='green':
        return green(s[a2+1:a3:])
    if s[a1+1:a2:]=='blue':
        return blue(s[a2+1:a3:])
# ---------------------------------------------------
def highlight_words(s, words):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    for e in words:
        s=s.replace(e,highlight(e))
    return s
# ---------------------------------------------------
def display_tag_file(filename):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    pass

6530177021: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display0.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 946, 'const': 622, 'code+const': 1568}
def red(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return RED+s+RESET
# ---------------------------------------------------
def green(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return GREEN+s+RESET
# ---------------------------------------------------
def blue(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return BLUE+s+RESET
# ---------------------------------------------------
def highlight(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return HIGHLIGHT+s+RESET
# ---------------------------------------------------
def color_text(s, color):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    c = color.upper()
    co = ['RED','GREEN','BLUE']
    if c == 'RED':
        return RED+s+RESET
    elif c == 'BLUE':
        return BLUE+s+RESET
    elif c== 'GREEN':
        return GREEN+s+RESET
    else:
        return s
# ---------------------------------------------------
def color_tag(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    #for e in s:
    i = s.find('<')
    f = s.find('>')
    l = s.find('</>')
    if s[i+1:f] == 'red':
        return RED+s[f+1:l]+RESET
    elif s[i+1:f] == 'blue':
        return BLUE+s[f+1:l]+RESET
    elif s[i+1:f] == 'green':
        return GREEN+s[f+1:l]+RESET
# ---------------------------------------------------
def highlight_words(s, words):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    news = ''
    n1 = 0
    n2 = 0
    strhl =[]
    stphl = []
    for e in words:
        i = 0
#         while i < (len(s)-len(e)+1):
        for q in range(len(s)):
            if s[i:i+len(e)] == e:
                strhl += [i]
                stphl += [i+len(e)]
                i+=len(e)
            else:
                i+=1
    strhl.sort()
    stphl.sort()
    if len(words) == 0:
        return s
    else :
        news+=s[:strhl[0]]+HIGHLIGHT+s[strhl[0]:stphl[0]]+RESET
        for i in range(1,len(strhl)):
            news += s[stphl[i-1]:strhl[i]]+HIGHLIGHT+s[strhl[i]:stphl[i]]+RESET
        news += s[stphl[-1]:]
        return news
# ---------------------------------------------------
def display_tag_file(filename):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    ans = ''
    c = []
    fn = open(filename,'r',encoding="utf-8")
    for i in fn:
        c+=[[i,i.count('</>')]]
    for i in range(len(c)):
        if c[i][0].find('<') != -1 :
            n = 0
            for q in range(c[i][1]):
                a = c[i][0].find('<',n)
                ans += c[i][0][n:a]+color_tag(c[i][0][a:])
                n = c[i][0].find('</>',n)+3
            ans += c[i][0][n:]
        else :
            ans += c[i][0]
    fn.close()
    return ans

6530178721: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_21.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display0.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 944, 'const': 470, 'code+const': 1414}
def red(s):
    return RED + s + RESET
# ---------------------------------------------------
def green(s):
    return GREEN + s + RESET
# ---------------------------------------------------
def blue(s):
    return BLUE + s + RESET
# ---------------------------------------------------
def highlight(s):
    return HIGHLIGHT + s + RESET
# ---------------------------------------------------
def color_text(s, color):
    color = color.lower()
    if color == 'red':
        return red(s)
    elif color == 'green':
        return green(s)
    elif color == 'blue':
        return blue(s)
    else:
        return s
# ---------------------------------------------------
def color_tag(s):
    m = s.find('>')
    color = s[1:m]
    n = s.find('</>')
    s = s[m+1:n]
    return color_text(s, color)
# ---------------------------------------------------
def highlight_words(s, words):
    for i in range(len(words)):
        ss = s.lower()
        words[i] = words[i].lower()
        mm = ss.find(words[i])
        s = s[:mm] + HIGHLIGHT + s[mm:mm+len(words[i])] + RESET + s[mm+len(words[i]):]
        ss = ss[:mm] + HIGHLIGHT + ss[mm:mm+len(words[i])] + RESET + ss[mm+len(words[i]):]
        while mm != -1:
            mm = ss.find(words[i],mm+len(words[i])+(len(HIGHLIGHT)+len(RESET)))
            if mm == -1:
                break
            s = s[:mm] + HIGHLIGHT + s[mm:mm+len(words[i])] + RESET + s[mm+len(words[i]):]
            ss = ss[:mm] + HIGHLIGHT + s[mm:mm+len(words[i])] + RESET + ss[mm+len(words[i]):]
    return s
# ---------------------------------------------------
def display_tag_file(filename):
    file1 = open(filename, 'r', encoding='utf-8')
    fn = file1.read()
    out = ''
    m = fn.find('<')
    n = fn.find('>')
    color = fn[m+1:n]
    close = fn.find('</>')
    s = fn[n+1:close]
    out = fn[:m] + color_text(s, color) + fn[close+3:]
    while m != -1:
        m = out.find('<',m+len(s)+len(RED)+len(RESET))
        if m == -1:
            break
        n = out.find('>',m)
        color = out[m+1:n]
        close = out.find('</>')
        s = out[n+1:close]
        out = out[:m] + color_text(s, color) + out[close+3:]     
    file1.close()
    return out

6530179321: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display1.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 342, 'const': 360, 'code+const': 702}
def red(s):
    return RED + s + RESET
# ---------------------------------------------------
def green(s):
    return GREEN + s + RESET
# ---------------------------------------------------
def blue(s):
    return BLUE + s + RESET
# ---------------------------------------------------
def highlight(s):
    return HIGHLIGHT + s + RESET
# ---------------------------------------------------
def color_text(s, color):
    if color.upper() == "RED":
      res = RED + s + RESET
    elif color.upper() == "GREEN":
      res = GREEN + s + RESET
    elif color.upper() == "BLUE":
      res = BLUE + s + RESET
    else:
      return s
    return res
# ---------------------------------------------------
def color_tag(s):
    res = s.replace("<red>", RED)
    res = res.replace("<green>", GREEN)
    res = res.replace("<blue>", BLUE)
    res = res.replace("</>", RESET)
    return res
# ---------------------------------------------------
def highlight_words(s, words):
    for w in words:
      s = s.replace(w, HIGHLIGHT + w + RESET)
    return s
# ---------------------------------------------------
def display_tag_file(filename):
    with open(filename, 'r', encoding='utf-8') as f :
      text = f.read()
      print(color_tag(text))

6530180921: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display0.0
abcrrrpkk

defgggocr

xyzbbbabc

abcrrrpf<green>gggorrz<blue>bbbabc
[]
bytecount: {'code': 848, 'const': 617, 'code+const': 1465}
def red(s):
    return RED + s + RESET
# ---------------------------------------------------
def green(s):
    return GREEN + s + RESET
# ---------------------------------------------------
def blue(s):
    return BLUE + s + RESET
# ---------------------------------------------------
def highlight(s):
    return HIGHLIGHT + s + RESET
# ---------------------------------------------------
def color_text(s, color):
    color = color.lower()
    if color == 'red':
        return red(s)
    elif color == 'green':
        return green(s)
    elif color == 'blue':
        return blue(s)
    else:
        return s
# ---------------------------------------------------
def color_tag(s):
    if '</>' in s:
        st = s.find('</>')
        if '<red>' in s:
            r = s.find('<red>') + 5
            s = s[r:st]
            tag = red(s)
        elif '<green>' in s:
            g = s.find('<green>') + 7
            s = s[g:st]
            tag = green(s)
        elif '<blue>' in s:
            b = s.find('<blue>') + 6
            s = s[b:st]
            tag = blue(s)
    return tag
# ---------------------------------------------------
def highlight_words(s, words):
    a = []
    for e in words:
        a.append(highlight(e))
    k = 0
    while k != len(words):
        if words[k] in s:
            s = s.replace(words[k], a[k])
        k+=1
    return s
# ---------------------------------------------------
def display_tag_file(filename):
    row = []
    f = open(filename, 'r', encoding='utf-8')
    for k in f:
        n = k.find('</>')+3
        k= k[:n] + '  ' + k[n:]
        row.append(k.split('  '))
    for i in range(len(row)):
        for e in range(len(row[i])):
            if '</>' in row[i][e]:
                row[i][e] = row[i][e].replace('</>',RESET)
            if '<red>' in row[i][e]:
                row[i][e] = row[i][e].replace('<red>',RED)
            elif '<green>' in row[i][e]:
                row[i][e] = row[i][e].replace('<green>',GREEN)
            elif '<blue>' in row[i][e]:
                row[i][e] = row[i][e].replace('<blue>',BLUE)
    for i in range(len(row)):
        for c in row[i]:
            row[i] = ''.join(row[i])
    for i in range(len(row)):
        print(row[i])
    f.close()

6530181521: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_10.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0mc']
test_highlight_20.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0mc']
test_display1.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 630, 'const': 507, 'code+const': 1137}
def red(s):
    return RED + s + RESET
# ---------------------------------------------------
def green(s):
    return GREEN + s + RESET
# ---------------------------------------------------
def blue(s):
    return BLUE + s + RESET
# ---------------------------------------------------
def highlight(s):
    return HIGHLIGHT + s + RESET
# ---------------------------------------------------
def color_text(s, color):
    if color.lower() == 'red' :
        return red(s)
    elif color.lower() == 'green' :
        return green(s)
    elif color.lower() == 'blue' :
        return blue(s)
    else :
        return s
# ---------------------------------------------------
def color_tag(s):
    stop = s.find('>')
    tag = s[1:stop].lower()
    text = s[stop+1:s.find('<',stop)]
    return color_text(text,tag)
# ---------------------------------------------------
def highlight_words(s, words):
    t = ''
    for w in words :
        S = s.lower()
        w = w.lower()
        start = S.find(w)
        stop = 0
        t = s[:start]
        while start != -1:
            c = s[start:start+len(w)]
            t += highlight(c)
            stop = start
            start = S.find(w,start+len(w))
            t += s[stop+len(w):start]
        s = t+s[-1]
    return s
# ---------------------------------------------------
def display_tag_file(filename):
    f = open(filename,'r',encoding="utf-8")
    t = ''.join(f.readlines())
    start = t.find('<')
    stop = t.find('>',t.find('>',start)+1)+1
    c = t[start:stop]
    text = t[:start]
    while start != -1:
        text += color_tag(c)
        start = t.find('<',stop)
        sm = t.find('>',start)+1
        text += t[stop:start]
        stop = t.find('</>',sm)+3
        c = t[start:stop]
    print(text+t[-1])

6530182121: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_10.0IndexError('string index out of range')
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0IndexError('string index out of range')
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display0.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 3610, 'const': 9722, 'code+const': 13332}
def red(s):
    s = str(s)
    s = RED+s+RESET
    return str(s)
# ---------------------------------------------------
def green(s):
    s = str(s)
    s = GREEN+s+RESET
    return str(s)
# ---------------------------------------------------
def blue(s):
    s = str(s)
    s = BLUE+s+RESET
    return str(s)
# ---------------------------------------------------
def highlight(s):
    s = str(s)
    s = HIGHLIGHT+s+RESET
    return str(s)
# --------------------------------------------------------------------------------------------------------------------------
def color_text(s, color):
    s = str(s)
    color = str(color)
    color = color.lower() #ตัดปัญหาตัวเล็กตัวใหญ่
    if color == "red" :
        out = red(s)
    elif color == "green" :
        out = green(s)
    elif color == "blue" :
        out = blue(s)
    else :
        out = s
    return str(out)
# --------------------------------------------------------------------------------------------------------------------------
def color_tag(s):
    s = str(s)
    out = ""
    if s[0] == "<" and s[1] == "r" and s[2] == "e" and s[3] == "d" and s[4] == ">":
        for i in range(5, len(s)):
          if s[i] == "<" and s[i+1] == "/" and s[i+2] == ">":
            break
          out += red(s[i])
    elif s[0] == "<" and s[1] == "g" and s[2] == "r" and s[3] == "e" and s[4] == "e" and s[5] == "n" and s[6] == ">":
        for i in range(7, len(s)):
          if s[i] == "<" and s[i+1] == "/" and s[i+2] == ">":
            break
          out += green(s[i])
    elif s[0] == "<" and s[1] == "b" and s[2] == "l" and s[3] == "u" and s[4] == "e" and s[5] == ">":
        for i in range(6, len(s)):
          if s[i] == "<" and s[i+1] == "/" and s[i+2] == ">":
            break
          out += blue(s[i])
    return str(out)
# --------------------------------------------------------------------------------------------------------------------------
def highlight_words(s, words):
    out = ""
    i=0
    if words != [] :
        while i < len(s):
          for w in words:
            w = w.lower()
            matching = ""
            string = ""
            for j in range(0, len(w)):
              if s[i+j].lower() == w[j]:
                matching += s[i+j].lower()
                string += s[i+j]
              else:
                matching = ""
                string = ""
                break
            if matching == w:
              out += highlight(string)
              i += len(w)
          if matching == "":
            out += s[i]
            i+=1
    else :
        out = s
    return str(out)
# --------------------------------------------------------------------------------------------------------------------------
def display_tag_file(filename):
    file = open(filename, "r", encoding='utf-8')
    line = ""
    for l in file:
      line += l
    color = "no color"
    out = ""
    i=0
    line_length = len(line)
    while i < line_length:
      #RED
        if line[i] == "<" and line[i+1] == "r" and line[i+2] == "e" and line[i+3] == "d" and line[i+4] == ">":
            i+=5
            keep=""
            while True:
              if line[i] == "<" and line[i+1] == "/" and line[i+2] == ">":
                i+=2
                break
              else:
                keep += line[i]
                i+=1
            out += color_tag("<red>"+keep+"</>")
        #GREEN
        elif line[i] == "<" and line[i+1] == "g" and line[i+2] == "r" and line[i+3] == "e" and line[i+4] == "e" and line[i+5] == "n" and line[i+6] == ">":
            i+=7
            keep=""
            while True:
              if line[i] == "<" and line[i+1] == "/" and line[i+2] == ">":
                i+=2
                break
              else:
                keep += line[i]
                i+=1
            out += color_tag("<green>"+keep+"</>")
        #BLUE
        elif line[i] == "<" and line[i+1] == "b" and line[i+2] == "l" and line[i+3] == "u" and line[i+4] == "e" and line[i+5] == ">":
            i+=6
            keep=""
            while True:
              if line[i] == "<" and line[i+1] == "/" and line[i+2] == ">":
                i+=2
                break
              else:
                keep += line[i]
                i+=1
            out += color_tag("<blue>"+keep+"</>")
        else:
            out += line[i]
        i+=1
    file.close()
    print(str(out))
# --------------------------------------------------------------------------------------------------------------------------
def test() :
    print("\033[;103mSeries 1\033[0m : โจทย์ที่ให้มาเลย")
    print("="*50)
    print()
    print("Function 1")
    print('red text:', red('red text'), 'and normal text')
    print('green text:', green('green text'), 'and normal text')
    print('blue text:', blue('blue text'), 'and normal text')
    print('highlight text:', highlight('highlight text'), 'and normal text')
    print()
    print()
    print("Function 2")
    print(color_text('This is red text', 'red'))
    print(color_text('This is green text', 'GreeN'))
    print(color_text('This is blue text', 'BLUE'))
    print(color_text('This is yellow text', 'yellow'))
    print()
    print()
    print("Function 3")
    print(color_tag('<red>red text</>'))
    print(color_tag('<green>green text</>'))
    print(color_tag('<blue>blue text</>'))
    print()
    print()
    print("Function 4")
    t = 'a[3]มิใช่ลิสต์ คืนค่ามิใช่print =มิใช่เปรียบเทียบ รักมิใช่ดวงดาวที่พราวแสง'
    print(t)
    print(highlight_words(t,['มิใช่']))
    print(highlight_words(t,['ลิสต์']))
    print(highlight_words(t, []))
    w = ['print', 'ดาว', 'มิใช่']
    z = highlight_words(t, w)
    print(z)
    print()
    print()
    print("Function 5")
    display_tag_file('a.txt')
    print()
    print("="*50)
    print("\033[;103mSeries 2\033[0m : เล่นลิ้น")
    print()
    print("Test 1")
    x = ["สวัสดีปีใหม่" , "สวัสดี gen phy" ,"ลาก่อน cal" , "ไอหยา materials" ,
         "ส้นตรีน Exploring","ลาก่อนเกรดผม" ,"เธอชื่ออะไร","ฉันชื่อเท่ง","แค่ก"]
    print(x)
    print("บรรทัด \033[;31mคี่ ปริ้นสีแดง\033[0m ; \033[;34mคู่ ปริ้นสีน้ำเงิน\033[0m")
    for i in range (len(x)) :
        if i % 2 == 0 :
            print("บรรทัดที่ "+str(i+1)+" ==> "+ color_text(x[i],"red"))
        else :
            print("บรรทัดที่ "+str(i)+" ==> "+ color_text(x[i],"blue"))
    print()
    print()
    print("Test 2")
    print("ปริ้นเลข 1-60")
    print("ถ้าหารด้วย 3 เศษ 1 --> สีแดง")
    print("ถ้าหารด้วย 3 เศษ 2 --> สีเขียว")
    print("ถ้าหารด้วย 3 เศษ 0 --> สีน้ำเงิน")
    x = [""]*60 ; i = 1
    for i in range (1,61) :
        if i % 3 == 1 :
            x[i-1] = color_tag(str(("<red>"+(str(i))+"</>")))
        elif i % 3 == 2 :
            x[i-1] = green(str(i))
        elif i % 3 == 0 :
            x[i-1] = color_text(str(i),"blue")
    print("["+", ".join(x)+"]")
    print()
    print()
    print("Test 3")
    s = "สวัสดี Dota2 เราอ่ะไม่เล่นนายหรอกนะ dota2 เพราะอะไรนะหรอ คอมเรากากฮะ เราเลยไปเล่น Elden ring กับ Overwatch2 \nแทนวันนี้วันดีนะทำไมหน่ะหรอ??? เพราะฉันพึ่งเริ่มทำการบ้านนี้ตอนวันที่ 16 5555+"
    print(s)
    print()
    #highlight_words(s, words)
    print("1.highlight : -ะ") ; k = ["ะ"]
    print(highlight_words(s, k))
    print()
    print("2.highlight : dota2") ; m = ["dota2"]
    print(highlight_words(s, m))
    print()
    print(color_text(s,"red"))
    print()
    print("3.Highlight ช่องว่าง แล้วทำอักษรสีแดง")
    print(color_text(highlight_words(s,[" "]),"red"))
    print()
    print("4.ทำอักษรสีแดงก่อน แล้วค่อย Highlight ช่องว่าง")
    print(highlight_words(color_text(s,"red"),[" "]))
    print()
    if (highlight_words(color_text(s,"red"),[" "])) == (color_text(highlight_words(s,[" "]),"red")) :
        print(blue("แบบ 3. กับ 4. ตรงกันจ้า!"))
    print()
    print("5.Highlight : เพราะ ,คนสวย ,วันนี้ ,วัน")
    k = ["เพราะ" ,"คนสวย" ,"วันนี้" ,"วัน"] ; print(highlight_words(s, k))
    print()
    print()
    print("Test 4")
    display_tag_file("x.txt")
    print()
    print()
    display_tag_file("y.txt")
    print("="*70)
# --------------------------------------------------------------------------------------------------------------------------
def test2():
    print("ฟังก์ชั่นนี้ ใช้ทดสอบกรณีพวกโบนัสโดยเฉพาะ")
    print("="*70)
    print("Test 1") ; print()
    display_tag_file("z.txt")
    print()
    print()
    print("="*70)
    print("Test 2") ; print()
    x = "Dota2 คือเกมๆ หนึ่งที่เราไม่เคยเล่น dota 1 ก็เช่นกันเราก็ไม่เคยคิดจะเล่น \nเพราะอะไรหน่ะครับ DOTA2 ใช้ spec อ่านว่า SPEC Ec เยอะ DOTA1 ก็เยอะเหมือนกัน แต่คิดจะไม่เล่นอยู่แล้ว \nOverwatch ก็เช่นกัน แต่ก็อยากเล่นอยู่ดี OVERWATCH อ่ะนะ โดยเฉพาะ OveRwaTcH2 อ่ะ เพราะ OverwAtCH1 มันไปแล้ว \nแล้วทำไม Materialches ยากจัง?"
    print(x)
    print()
    p = ['d'] 
    print("1.Highlight คำว่า d ==>\n"+highlight_words(x,p)) ; print()
    p = ["D"]
    print("2.Highlight คำว่า D ==>\n"+highlight_words(x,p)) ; print()
    h = ["ก","ข","จ"] 
    print("3.Highlight คำว่า ก ,ข และ จ ==>\n"+highlight_words(x,h)) ; print() 
    p = ["dota"]
    print("4.Highlight คำว่า dota ==>\n"+highlight_words(x,p)) ; print()
    m = ["DotA","เล่น"]
    print("5.Highligh คำว่า DotA และ เล่น ==>\n"+highlight_words(x,m)) ; print()
    o = x ; print("5.5.Highlight คำว่า dota OVERWATCH และ เล่น \ ==>\n"+highlight_words(o,["DOTA","เล่น","OveRwaTcH"])) ; print()
    print("6.Highlight คำว่า ch ,ec,Ov,r และ เล่น ==>\n"+highlight_words(x,['ch' ,'ec','Ov','r','เล่น'])) ; print()
    print("7.Highlight คำว่า o ช่องว่าง และ a ==>\n"+highlight_words(x,["o"," ","a"])) ; print()
    print("8.Highlight คำว่า 2 d และ คิด ==>\n"+highlight_words(x,["2","d","คิด"])) 
    print()
    print("="*70)
    print("Test 3") ; print()
    display_tag_file("w.txt")
    print()
    print("="*70)
    print("Test 4") ; print()
    display_tag_file("BonustestforHw4.txt")
    print()
    print("="*70)
    print("Test 5")
    print()
    pb = "On offering to The blind man, tHE man whO then stOlE his car,had\n, at THat prEcisE moment, hAd  Evil IntentIOn, quIte THE contrAry, whAt he did\nwAs nothIng mOre than obEy those feelings Of gEneROsity AltrUism wHich,\nEveryoNe knows, ArE the twO best  trAits of human nature to be fOund\nmUch more hArdeNEd crIminals thAn this one, a simple car-thief without\nhope of AdvAncing his prOfession, ExplOited bY the real OwnErs of tHis\nEnterPRiSe, it hey who take advantage oF tHe needs of ThE pOor."
    print(pb);print()
    print("1.Highlight คำว่า on the ==>\n"+highlight_words(pb,["on","the"]));print()
    print("2.Highlight คำว่า a,e,i,o,u ==>\n"+highlight_words(pb,["a","i","u","o","e"]));print()
    print("3.Highlight ช่องว่าง ==>\n"+highlight_words(pb,[" "]));print()
    print("4.Highlight คำว่า is,am,are,was,wh ==>\n"+highlight_words(pb,["is","am","are","are","was","wh"]));print()

6530183821: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display0.0FileNotFoundError("No such file or directory: 'มหาจุฬาลงกรณ์-tag.txt'")
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 736, 'const': 748, 'code+const': 1484}
def c_index(s,t,start):
    for i in range(start,len(s)):
        if s[i]==t:
            return i
    return -1
# ---------------------------------------------------
def red(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return RED+s+RESET
# ---------------------------------------------------
def green(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return GREEN+s+RESET
# ---------------------------------------------------
def blue(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return BLUE+s+RESET
# ---------------------------------------------------
def highlight(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return HIGHLIGHT+s+RESET
# ---------------------------------------------------
def color_text(s, color):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    if color=="red":
        s=red(s)
    elif color=="GreeN":
        s=green(s)
    elif color=="BLUE":
        s=blue(s)
    return s
# ---------------------------------------------------
def color_tag(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    i1=c_index(s,"<",0)
    i2=c_index(s,">",i1+1)
    i3=c_index(s,"<",i2+1)
    color=s[i1+1:i2]
    r=s[i2+1:i3]
    if color=="red":
        r=red(r)
    elif color=="blue":
        r=blue(r)
    elif color=="green":
        r=green(r)
    return r
# ---------------------------------------------------
def highlight_words(s, words):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    for i in range(len(words)):
        s=s.split(words[i])
        s=highlight(words[i]).join(s)
    return s
# ---------------------------------------------------
def tagging(s):
    s=s.split("</>")
    l=[]
    for i in range(len(s)):
      i1=c_index(s[i],"<",0)
      if i1!=-1:
        i2=c_index(s[i],">",i1+1)
        color=s[i][i1+1:i2]
        r=s[i][i2+1:]
        l.append(s[i][0:i1])
        if color=="red":
          r=red(r)
        elif color=="blue":
          r=blue(r)
        elif color=="green":
          r=green(r)
        l.append(r)
      else:
        l.append(s[i][0:])
    return "".join(l)
def display_tag_file(filename):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    fn=open('มหาจุฬาลงกรณ์-tag.txt',"r",encoding='utf-8')
    for line in fn:
      print(tagging(line))
    fn.close()

6530185021: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display0.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 692, 'const': 835, 'code+const': 1527}
def red(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return '\033[;31m'+s+'\033[0m'
# ---------------------------------------------------
def green(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return '\033[;32m'+s+'\033[0m'
# ---------------------------------------------------
def blue(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return '\033[;34m'+s+'\033[0m'
# ---------------------------------------------------
def highlight(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return '\033[;103m'+s+'\033[0m'
# ---------------------------------------------------
def color_text(s, color):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    if color.lower() == "red":
         return red(s)
    elif color.lower() == "green":
         return green(s)
    elif color.lower() == "blue":
         return blue(s)
    else:
         return s
# ---------------------------------------------------
def color_tag(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    x = s.split("<")
    y = x[1]
    y = y.split(">")
    color = y[0]
    if color == "red":
         return red(y[1])
    elif color == "green":
         return green(y[1])
    elif color == "blue":
         return blue(y[1])
# ---------------------------------------------------
def highlight_words(s, words):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    if words == []:
        return s
    else:
        for x in words:
            s = s.replace(x,highlight(x))
        return s         
# ---------------------------------------------------
def display_tag_file(filename):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    f = open(filename, "r",  encoding='utf-8')
    answer = ""
    for line in f:
        a = f.readline()
        x = a.split("</>")
        for i in range(len(x)):
           if "<red>" in x[i]:
               answer += x[i][:x[i].find("<red>")] + red(x[i][x[i].find("<red>")+5:])
           elif "<green>" in x[i]:
               answer += x[i][:x[i].find("<green>")] + green(x[i][x[i].find("<green>")+7:])
           elif "<blue>" in x[i]:
               answer += x[i][:x[i].find("<blue>")] + blue(x[i][x[i].find("<blue>")+6:])
           else:
               answer += x[i]
    f.close()
    print(answer)

6530186721: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_10.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display1.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 844, 'const': 737, 'code+const': 1581}
def red(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    s = str(s)
    s = RED + s + '\033[0m'
    return s
# ---------------------------------------------------
def green(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    s = str(s)
    s = GREEN + s + '\033[0m'
    return s
# ---------------------------------------------------
def blue(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    s = str(s)
    s = BLUE + s + '\033[0m'
    return s
# ---------------------------------------------------
def highlight(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    s = str(s)
    s = HIGHLIGHT + s + '\033[0m'
    return s
# ---------------------------------------------------
def color_text(s, color):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    s = str(s)
    color = str(color)
    color = color.lower()
    if color == 'red' :
        return red(s)
    elif color == 'green' :
        return green(s)
    elif color == 'blue' :
        return blue(s)
    else :
        return s
# ---------------------------------------------------
def color_tag(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    s = str(s)
    x = s.split('>')
    color = x[0][1:]
    text = x[1][:-2]
    s = color_text(text, color)
    return s
# ---------------------------------------------------
def highlight_words(s, words):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    flag = []
    c = 0
    for e in words :
        upper = e.upper()
        lower = e.lower()
        for n,i in enumerate(s):
            if i == upper[c] or i == lower[c] :
                c += 1
                if c == len(e) :
                    flag.append([n+1-len(e),n+1])
                    c = 0
            else :
                c = 0
    flag.sort()
    sol = s
    for i in flag[-1::-1] :
        sol = sol[:i[0]] + HIGHLIGHT + sol[i[0]:i[1]] + '\033[0m' + sol[i[1]:]
    return sol
# ---------------------------------------------------
def display_tag_file(filename):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    data = ''
    with open(filename, 'r', encoding= 'utf-8') as file :
        for line in file :
            data += line
    read_state = 0
    command = ''
    sol = ''
    for i in data :
        if i == '<' :
            if read_state == 1 :
                sol += '<' + command + i
                command = ''
            else :
                read_state = 1
        elif i == '>' :
            command = command.upper()
            if command == 'RED' :
                sol += RED
            elif command == 'GREEN' :
                sol += GREEN
            elif command == 'BLUE' :
                sol += BLUE
            elif command == '/' :
                sol += '\033[0m'
            else :
                sol += '<' + command + i
            command = ''
            read_state = 0
        elif read_state == 1 :
            command += i
        else :
            sol += i
    if read_state == 1 :
        read_state = 0
        sol += '<' + command
    print(sol)

6530187321: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_21.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display1.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 866, 'const': 537, 'code+const': 1403}
def red(s):
    a = RED + s + RESET
    return a
# ---------------------------------------------------
def green(s):
    a = GREEN + s + RESET
    return a
# ---------------------------------------------------
def blue(s):
    a = BLUE + s + RESET
    return a
# ---------------------------------------------------
def highlight(s):
    a = HIGHLIGHT + s + RESET
    return a
# ---------------------------------------------------
def color_text(s, color):
    color = color.lower().strip()
    if color == 'red':
        s = red(s)
    elif color == 'green':
        s = green(s)
    elif color == 'blue':
        s = blue(s)
    else: pass
    return s
# ---------------------------------------------------
def color_tag(s):
    a = s.find('<')
    b = s.find('>')
    c = s.find('<', a + 1 )
    x = s[b+1:c]
    color = s[a+1:b].lower().strip()
    if color == 'red':
        x = red(x)
    elif color == 'green':
        x = green(x)
    elif color == 'blue':
        x = blue(x)
    else: pass
    return x
# ---------------------------------------------------
def highlight_words(s, words):
    for e in words:
        c = 0
        x = 0
        e = e.strip()
        for i in range(len(s)):
            if s[i:i+len(e)].lower() == e.lower():
                x += 1
        for i in range(x):
            y = s.lower()
            a = y.find(e.lower(),c)
            s = s[:a] + highlight(s[a:a+len(e)]) + s[a + len(e):]
            c = a + len(highlight(e))
    return s           
# ---------------------------------------------------
def display_tag_file(filename):
    x = open(filename, 'r', encoding='utf-8')
    s = ''
    q = ''
    y = 0
    for line in x:
        for e in line:
            if e == '<':
                y += 1
        q += line
    y //= 2
    d = 0
    if y >= 1:
        for i in range(y-1):
            a = q.find('<',d)
            b = q.find('>',d)
            c = q.find('>', b + 1 ) + 1
            s += q[d:a] + color_tag(q[a:c])
            d = c
        a = q.find('<',d)
        b = q.find('>',d)
        c = q.find('>', b + 1 ) + 1
        s += q[d:a] + color_tag(q[a:c]) + q[c:]
    else:
        s += q
    x.close()
    print(s)

6530188021: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_10.0TypeError('can only concatenate str (not "module") to str')
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0TypeError('can only concatenate str (not "module") to str')
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display0.0TypeError('can only concatenate str (not "module") to str')
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 1152, 'const': 922, 'code+const': 2074}
def red(w):
    r = '\033[;31m'
    sol = r + w + re
    return sol
def green(w):
    g = '\033[;32m'
    sol = g + w + re
    return sol
def blue(w):
    b = '\033[;34m'
    sol = b + w + re
    return sol
def highlight(w):
    hi = '\033[;103m'
    sol = hi + w + re
    return sol
def color_text(s, color):
    c = color.lower()
    if c == 'red':
        return red(s)
    elif c == 'blue':
        return blue(s)
    elif c == 'green':
        return green(s)
    else:
        return s
def color_tag(s):
    x = s.split('>')
    x = x[1].split('<')
    w = x[0]
    if s.find('red') == 1:
        return red(w)
    elif s.find('green') == 1:
        return green(w)
    elif s.find('blue') == 1:
        return blue(w)
def highlight_words(s, words):
    l = s.lower()
    o = list(s)
    if type(words) == list :
        for e in range(len(words)):
            w = words[e]
            n = len(w)
            i = 0
            while i != -1:
                i = l.find(w.lower(),i)
                if i != -1:
                    for c in range(n):
                        o[i+c] = highlight(o[i+c])
                if i != -1 :
                    i+=1
    else:
        w = words
        n = len(w)
        i = 0
        while i != -1:
            i = l.find(w.lower(),i)
            if i != -1:
                for c in range(n):
                    o[i+c] = highlight(o[i+c])
            if i != -1 :
                i+=1
    sol = ''.join(o)
    return sol
def fck(w):
    sol = []
    m = ''
    x = w.split('</>')
    if type(x) == list:
        for e in range(len(x)):
            if x[e].find('red')!= -1:
                k = x[e].split('<red>')
                if len(k) == 1:
                    sol += [red(k[0])]
                else:
                    sol += [k[0]+red(k[1])]
            elif x[e].find('blue')!= -1:
                k = x[e].split('<blue>')
                if len(k) == 1:
                    sol += [blue(k[0])]
                else:
                    sol += [k[0]+blue(k[1])]
            elif x[e].find('green')!= -1:
                k = x[e].split('<green>')
                if len(k) == 1:
                    sol += [green(k[0])]
                else:
                    sol += [k[0]+green(k[1])]
            elif x[e].find('highlight')!= -1:
                k = x[e].split('<highlight>')
                if len(k) == 1:
                    sol += [highlight(k[0])]
                else:
                    sol += [k[0]+highlight(k[1])]
            else:
                sol += [x[e]]
        m += ''.join(sol)
        return m
    else:
        return x
def display_tag_file(filename):#color_tag2
    sol = ''
    web = open(str(filename),'r')
    for line in web:
         sol += line
    print(fck(sol))

6530189621: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display1.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 346, 'const': 750, 'code+const': 1096}
def red(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return '\033[;31m'+s+'\033[0m'
# ---------------------------------------------------
def green(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return '\033[;32m'+s+'\033[0m'
# ---------------------------------------------------
def blue(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return '\033[;34m'+s+'\033[0m'
# ---------------------------------------------------
def highlight(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return '\033[;103m'+s+'\033[0m'
# ---------------------------------------------------
def color_text(s, color):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    color=color.lower()
    if color=='red':
        return red(s)
    elif color=='blue':
        return blue(s)
    elif color=='green':
        return green(s)
    else:
        return s
# ---------------------------------------------------
def color_tag(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    s=s.replace('</>','\033[0m').replace('<red>','\033[;31m').replace('<blue>','\033[;34m').replace('<green>','\033[;32m')
    return s
# ---------------------------------------------------
def highlight_words(s, words):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    for i in range(len(words)):
        s=s.replace(words[i],highlight(words[i]))
    return s
# ---------------------------------------------------
def display_tag_file(filename):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    f=open(filename, 'r', encoding='utf-8')
    a=''
    for i in f:
      a+=i
    f.close()
    a=color_tag(a)
    print(a)

6530190121: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display1.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 658, 'const': 478, 'code+const': 1136}
def red(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    s_red = RED +s+ RESET
    return s_red
# ---------------------------------------------------
def green(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    s_green = GREEN +s+ RESET
    return s_green
# ---------------------------------------------------
def blue(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    s_blue = BLUE +s+ RESET
    return s_blue
# ---------------------------------------------------
def highlight(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    s_highlight = HIGHLIGHT +s+ RESET
    return s_highlight
# ---------------------------------------------------
def color_text(s, color):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    if color.lower() == 'red' :
        s_color_red = red(s)
        return s_color_red
    elif color.lower() == 'green' :
        s_color_green = green(s)
        return s_color_green
    elif color.lower() == 'blue':
        s_color_blue = blue(s)
        return s_color_blue
    else:
        return s
# ---------------------------------------------------
def color_tag(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    close_right = s.find('>')
    close_left = s.find('<' ,close_right)
    s_color_tag = s[close_right+1:close_left]
    outcome = color_text(s_color_tag ,s[1:close_right])
    return outcome
# ---------------------------------------------------
def highlight_words(s, words):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    for i in range(0, len(words)):
        start = 0
        x = s.find(words[i],start)
        while x != -1:
            x = s.find(words[i],start)
            if x == -1:
                break
            text_hgl = highlight(s[x: x+len(words[i])])
            s = s[0:x]+text_hgl+s[x+len(words[i]):]
            start = x+len(text_hgl)
    return s
# ---------------------------------------------------
def display_tag_file(filename):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    infile = open(filename,'r',encoding = 'utf-8')
    final_ans = ''
    while True:
        s = infile.readline()
        if s == '':
            break
        start = 0
        for i in range(0,len(s)):
            close_left = s.find('<',start)
            if close_left == -1:
                break
            close_right2 = s.find('</>',close_left)
            close_right = s.find('>',close_right2)
            x = s[close_left:close_right+1]
            x_color_tag = color_tag(x)
            s = s[0:close_left]+x_color_tag+s[close_right+1:]
            start = close_left + len(x_color_tag)
        final_ans += s
    print(final_ans)
    infile.close()

6530191821: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display1.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 524, 'const': 781, 'code+const': 1305}
def red(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    s='\033[;31m'+s+'\033[0m'
    return s
# ---------------------------------------------------
def green(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    s='\033[;32m'+s+'\033[0m'
    return s
# ---------------------------------------------------
def blue(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    s='\033[;34m'+s+'\033[0m'
    return s
# ---------------------------------------------------
def highlight(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    s='\033[;103m'+s+'\033[0m'
    return s
# ---------------------------------------------------
def color_text(s, color):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    color=color.lower()
    if color=='red':
        s=red(s)
        return s
    if color=='green':
        s=green(s)
        return s
    if color=='blue':
        s=blue(s)
        return s
    else:
        return s
# ---------------------------------------------------
def color_tag(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    for e in s:
        n1=s.find('<',)
        n2=s.find('>',n1+1)
        n=s[n1+1:n2]
        color=n
        n3=s.find('<',n2+1)
        s=s[n2+1:n3]
        if n=='red':
            return color_text(s, color)
        if n=='green':
            return color_text(s, color)
        if n=='blue':
            return color_text(s, color)
# ---------------------------------------------------
def highlight_words(s, words):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    for i in range(len(words)):
        s=s.replace(words[i],HIGHLIGHT+words[i]+RESET)
    return s
# ---------------------------------------------------
def display_tag_file(filename):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    z=''
    x=open(filename, 'r', encoding='utf-8')
    for k in x:
        z+=k
    z=z.replace('<red>',RED)
    z=z.replace('</>',RESET)
    z=z.replace('<green>',GREEN)
    z=z.replace('<blue>',BLUE)
    print(z)

6530192421: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_21.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display0.0
abcrrrpkk

defgggocr

xyzbbbabc

abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 516, 'const': 1019, 'code+const': 1535}
def red(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return '\033[;31m'+s+'\033[0m'
# ---------------------------------------------------
def green(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return '\033[;32m'+s+'\033[0m'
# ---------------------------------------------------
def blue(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return '\033[;34m'+s+'\033[0m'
# ---------------------------------------------------
def highlight(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return '\033[;103m'+s+'\033[0m'
# ---------------------------------------------------
def color_text(s, color):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    c = color.lower()
    if c == 'red':
        return red(s)
    elif c == 'green':
        return green(s)
    elif c == 'blue':
        return blue(s)
    else:
        return s
# ---------------------------------------------------
def color_tag(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    s = s.replace('<blue>','\033[;34m')
    s = s.replace('<red>','\033[;31m')
    s = s.replace('<green>','\033[;32m')
    s = s.replace('</>','\033[0m')
    return s
# ---------------------------------------------------
def highlight_words(s, words):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    v = s.lower()
    for i in words:
        if i.lower() in s.lower():
            v = v.replace(i.lower(),highlight(i.lower()))
    u = ''
    k = 0
    for i in range(len(v)):
        if v[i] == s[k].lower() or v[i] == s[k].upper():
            u += s[k]
        else:
            u += v[i]
            continue
        if k < len(s)-1:
            k += 1
    return u
# ---------------------------------------------------
def display_tag_file(filename):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    p = open(filename, 'r', encoding='utf-8')
    for line in p:
        line = line.replace('<blue>','\033[;34m')
        line = line.replace('<red>','\033[;31m')
        line = line.replace('<green>','\033[;32m')
        line = line.replace('</>','\033[0m')
        print(line)
    p.close()

6530193021: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_10.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display1.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 992, 'const': 671, 'code+const': 1663}
def red(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return RED+str(s)+RESET
# ---------------------------------------------------
def green(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return GREEN+str(s)+RESET
# ---------------------------------------------------
def blue(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return BLUE+str(s)+RESET
# ---------------------------------------------------
def highlight(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return HIGHLIGHT+str(s)+RESET
# ---------------------------------------------------
def color_text(s, color):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    if color.lower() == 'red':
        return red(s)
    elif color.lower() == 'green':
        return green(s)
    elif color.lower() == 'blue':
        return blue(s)
    else :
        return s          
# ---------------------------------------------------
def color_tag(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    if '<red>' in s :
        return red(s[5:-3])
    elif  '<green>' in s  :
        return green(s[7:-3])
    elif  '<blue>' in s  :
        return blue(s[6:-3])
# ---------------------------------------------------
def highlight_words(s, words):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    original = s
    for word in words:
        s = original.lower().split(word.lower())
        txt = ""
        k = 0
        for i in s:
            for j in i:
                txt += original[k]
                k += 1
            if (i == s[-1]): break
            txt += HIGHLIGHT
            for j in range(len(word)):
                txt += original[k]
                k += 1
            txt += RESET    
        original = txt                
    return original
# ---------------------------------------------------
def display_tag_file(filename):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    filename = open(filename, 'r', encoding='utf-8')
    b =[]
    last = None
    while True :
        a = filename.readline()
        if len(a) > 0 :
            a = a.split('</>')
            for i in range(len(a)) :
                if  '<red>' in a[i] :
                    a[i] = a[i][:a[i].find('<red>')] +RED+a[i][a[i].find('<red>')+5:]+RESET
                    b.append(a[i])
                    if i == len(a) - 1:
                        last = RED                   
                elif  '<green>' in a[i] :
                    a[i] = a[i][:a[i].find('<green>')] +GREEN+a[i][a[i].find('<green>')+7:]+RESET
                    b.append(a[i])
                    if i == len(a) - 1:
                        last = GREEN                
                elif  '<blue>' in a[i] :
                    a[i] = a[i][:a[i].find('<blue>')] +BLUE+a[i][a[i].find('<blue>')+6:]+RESET
                    b.append(a[i])
                    if i == len(a) - 1:
                        last = BLUE
                elif not last:
                    b.append(a[i])
                else:
                    b.append(last + a[i] + RESET)
                if i < len(a) - 1 and len(a) > 1:
                    last = None                  
        else :
            break
    print(''.join(b))
    filename.close()

6530194721: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_10.0
['\x1b[;103ma\x1b[0m\x1b[;103mb\x1b[0m\x1b[;103mc\x1b[0mde\x1b[;103mf\x1b[0m\x1b[;103mg\x1b[0m\x1b[;103ma\x1b[0m\x1b[;103mb\x1b[0m\x1b[;103mc\x1b[0mabbcbf\x1b[;103mf\x1b[0m\x1b[;103mg\x1b[0mcd\x1b[;103ma\x1b[0m\x1b[;103mb\x1b[0m\x1b[;103mc\x1b[0maa\x1b[;103ma\x1b[0m\x1b[;103mb\x1b[0m\x1b[;103mc\x1b[0m']
test_highlight_20.0
['\x1b[;103ma\x1b[0m\x1b[;103mB\x1b[0m\x1b[;103mC\x1b[0mde\x1b[;103mf\x1b[0m\x1b[;103mg\x1b[0m\x1b[;103mA\x1b[0m\x1b[;103mb\x1b[0m\x1b[;103mc\x1b[0mAbbcbf\x1b[;103mf\x1b[0m\x1b[;103mG\x1b[0mcd\x1b[;103ma\x1b[0m\x1b[;103mb\x1b[0m\x1b[;103mc\x1b[0maa\x1b[;103ma\x1b[0m\x1b[;103mb\x1b[0m\x1b[;103mc\x1b[0m']
test_display1.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 498, 'const': 763, 'code+const': 1261}
def red(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    a = '\033[;31m'+s+'\033[0m'
    return(a)
# ---------------------------------------------------
def green(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    a = '\033[;32m'+s+'\033[0m'
    return(a)
# ---------------------------------------------------
def blue(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    a = '\033[;34m'+s+'\033[0m'
    return(a)
# ---------------------------------------------------
def highlight(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    a = '\033[;103m'+s+'\033[0m'
    return(a)
# ---------------------------------------------------
def color_text(s, color):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    a = color.lower()
    if a == 'red':
      return(red(s))
    elif a == 'green':
      return(green(s))
    elif a == 'blue':
      return(blue(s))
    else:
      return(s)
# ---------------------------------------------------
def color_tag(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    s = s.replace('<red>','\033[;31m').replace('<green>','\033[;32m').replace('<blue>','\033[;34m').replace('</>','\033[0m')
    return(s)
# ---------------------------------------------------
def highlight_words(s, words):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    ind = []
    for i in range(len(words)):
      lS = s.lower()
      f = words[i].lower()
      pos = -1
      while True:
        pos = lS.find(f,pos+1)
        if(pos == -1):
          break
        for j in range(len(f)):
          ind.append(pos+j)
    ind.sort()
    g = -1
    while len(ind) != 0:
      a = ind.pop()
      if(a != g):
        s = s[:a] + highlight(s[a:a+1]) + s[a + 1:]
      g = a
    return s        
# ---------------------------------------------------
def display_tag_file(filename):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    r = open(filename, 'r', encoding='utf-8')
    txt = r.read()
    txt = color_tag(txt)
    a= print(txt)
    return(a)

6530195321: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display1.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 328, 'const': 360, 'code+const': 688}
def red(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return RED+s+RESET
# ---------------------------------------------------
def green(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return GREEN+s+RESET
# ---------------------------------------------------
def blue(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return BLUE+s+RESET
# ---------------------------------------------------
def highlight(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return HIGHLIGHT+s+RESET
# ---------------------------------------------------
def color_text(s, color):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    color_upper = color.upper()
    if color_upper == "RED":
        return red(s)
    elif color_upper == "GREEN":
        return green(s)
    elif color_upper == "BLUE":
        return blue(s)
    else:
        return s
# ---------------------------------------------------
def color_tag(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    output = s
    output = output.replace('<red>', RED)
    output = output.replace('<green>', GREEN)
    output = output.replace('<blue>', BLUE)
    output = output.replace('</>', RESET)
    return output
# ---------------------------------------------------
def highlight_words(s, words):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    for word in words:
        s = s.replace(word, highlight(word))
    return s
# ---------------------------------------------------
def display_tag_file(filename):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    f = open(filename, 'r', encoding='utf-8') 
    s = f.read()
    print(color_tag(s))
    f.close()

6530196021: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display0.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 578, 'const': 859, 'code+const': 1437}
def red(s):
  s = '\033[;31m'+s+'\033[0m'
  return s
# ---------------------------------------------------
def green(s):
  s = '\033[;32m'+s+'\033[0m'
  return s
# ---------------------------------------------------
def blue(s):
  s = '\033[;34m'+s+'\033[0m'
  return s
# ---------------------------------------------------
def highlight(s):
  s = '\033[;103m'+s+'\033[0m'
  return s
# ---------------------------------------------------
def color_text(s, color):
  color = color.lower()
  if color == 'red':
    return red(s)
  elif color == 'green':
    return green(s)
  elif color == 'blue':
    return blue(s)
  else:
    return s
# ---------------------------------------------------
def color_tag(s):
  a = ''
  for e in s:
    if e in ' <>/':
      a += ' '
    else:
      a += e
  b = a.split()
  word = b[1:]
  word = ' '.join(word)
  if b[0] == 'red':
    return red(word)
  elif b[0] == 'green':
    return green(word)
  elif b[0] == 'blue':
    return blue(word)
# ---------------------------------------------------
def highlight_words(s, words):
  for e in words:
    x = s.split(e)
    ans = highlight(e).join(x)
    s = ans
  return s
# ---------------------------------------------------
def display_tag_file(filename):
  file = open(filename, 'r', encoding='utf-8')
  for line in file:
    p1 = line.find('<')
    p2 = line.find('/')
    ans = ''
    for e in line:
      if line.find(e) != p1:
        ans += e
      else:
        ans += ",color_tag('"
        break
    for i in range(p1,len(line)):
      if i != p2+2:
        ans += line[i]
      else:
        ans += "'),"+line[i:]
        break
    ans = ans.split(',')
  file.close()
  return ans

6530197621: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_21.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display1.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 776, 'const': 532, 'code+const': 1308}
def red(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return RED + s + RESET
# ---------------------------------------------------
def green(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return GREEN + s + RESET
# ---------------------------------------------------
def blue(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return BLUE + s + RESET
# ---------------------------------------------------
def highlight(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return HIGHLIGHT + s + RESET
# ---------------------------------------------------
def color_text(s, color):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    c_up = color.upper()
    if c_up == "RED":
        return red(s)
    elif c_up == "BLUE":
        return blue(s)
    elif c_up == "GREEN":
        return green(s)
    else:
        return s
# ---------------------------------------------------
def color_tag(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    t1f = 0
    t1l = s.find(">")
    clr = s[t1f+1:t1l]
    t2f = s.find("</>",t1l)
    ans = s[t1l+1:t2f]
    return color_text(ans, clr)
# ---------------------------------------------------
def highlight_words(s, words):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    ans = s
    anslow = ans.lower()
    for w in words:
        idx = 0
        idx = anslow.find(w.lower(),idx)
        while idx != -1:
            highed = highlight(ans[idx:idx+len(w)])
            ans = ans[0:idx] + highed + ans[idx+len(w):]
            anslow = ans.lower()
            idx = anslow.find(w.lower(),idx+len(highed))
    return ans
# ---------------------------------------------------
def display_tag_file(filename):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    file1 = open(filename, 'r', encoding='utf-8')
    ans = ""
    line = file1.readline()
    lasttag = "</>"
    while line != "":
        line = line.strip()
        #Each Line==========================
        t1f = line.find("<")
        if line[t1f:t1f+3] == "</>":
            line = lasttag + line
            t1f = line.find("<")
        if t1f == -1 and lasttag != "</>":
            line = lasttag + line + "</>"
            line = color_tag(line)
        while t1f != -1:
            t1l = line.find(">",t1f)
            if t1l == -1:
                break
            tagsize = t1l - t1f + 1
            t2f = line.find("</>",t1f)
            if t2f == -1:
                lasttag = line[t1f:t1l+1]
                line = line + "</>"
                t2f = line.find("<",t1f+tagsize)
            else:
                lasttag = "</>"
            colored = color_tag(line[t1f:t2f+3])
            line = line[0:t1f] + colored + line[t2f+3:]
            t1f = line.find("<",t1f+1)
        ans += line + "\n"
        #===================================
        #print(lasttag)
        line = file1.readline()
    file1.close()
    print(ans.strip())

6530198221: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_10.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display1.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 388, 'const': 895, 'code+const': 1283}
def red(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    r = '\033[;31m'+s+'\033[0m'
    return r
# ---------------------------------------------------
def green(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    g = '\033[;32m'+s+'\033[0m'
    return g
# ---------------------------------------------------
def blue(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    b = '\033[;34m'+s+'\033[0m'
    return b
# ---------------------------------------------------
def highlight(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    h = '\033[;103m'+s+'\033[0m'
    return h
# ---------------------------------------------------
def color_text(s, color):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    color = color.lower()
    if color == 'red' :
      s = '\033[;31m'+s+'\033[0m'
    elif color == 'green' :
      s = '\033[;32m'+s+'\033[0m'
    elif color == 'blue' :
      s = '\033[;34m'+s+'\033[0m'
    else :
      s = s
    return s
# ---------------------------------------------------
def color_tag(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    x = s.replace('<red>',RED).replace('<blue>',BLUE).replace('<green>',GREEN).replace('</>',RESET)
    return x
# ---------------------------------------------------
def highlight_words(s, words):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    for i in range(len(words)) :
      x = s.replace(words[i],HIGHLIGHT+words[i]+RESET)
    return x
# ---------------------------------------------------
def display_tag_file(filename):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    f = open(filename, 'r', encoding='utf-8')
    for line in f :
      x = line.replace('<red>',RED).replace('<blue>',BLUE).replace('<green>',GREEN).replace('</>',RESET)
      print(x,end='')
    f.close()

6530199921: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_21.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display0.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 854, 'const': 795, 'code+const': 1649}
def red(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return '\033[;31m'+s+'\033[0m'
# ---------------------------------------------------
def green(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return '\033[;32m'+s+'\033[0m'
# ---------------------------------------------------
def blue(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return '\033[;34m'+s+'\033[0m'
# ---------------------------------------------------
def highlight(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return '\033[;103m'+s+'\033[0m'
# ---------------------------------------------------
def color_text(s, color):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    if not color.upper() in ['RED', 'GREEN', 'BLUE'] :
        return s
    else :
        if color.upper() == 'RED' :
            return red(s)
        elif color.upper() == 'GREEN' :
            return green(s)
        elif color.upper() == 'BLUE' :
            return blue(s)
# ---------------------------------------------------
def color_tag(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    i1 = s.find('>')
    s1 = s[i1+1:]
    i2 = s1.find('<')
    s2 = s1[:i2]
    color = s[1:i1]
    if color.upper() == 'RED' :
        return red(s2)
    elif color.upper() == 'GREEN' :
        return green(s2)
    elif color.upper() == 'BLUE' :
        return blue(s2)
# ---------------------------------------------------
def highlight_words(s, words):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
   ans = ''
   n = 0
   for i in range(len(s)) :
      for j in range(len(words)) :
            if s[i].upper() == words[j][0].upper() and s[i].lower() == words[j][0].lower() :
                if s[i: i+len(words[j])].upper() == words[j].upper() and s[i: i+len(words[j])].lower() == words[j].lower() :
                    ans += s[n:i] + highlight(s[i:i+len(words[j])])
                    n = i+len(words[j])
   ans += s[n:]
   return ans
# ---------------------------------------------------
def display_tag_file(filename):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
   file = open(filename, encoding="utf-8")
   ans = ''
   n = 0
   getChar = False
   getColor = False
   dontGet = False
   color = ''
   char = ''
   for line in file :
       for i in range(len(line)) :
           if line[i] == '<' and not getColor and not getChar:
             getColor = True
           elif line[i] == '>' and getColor:
             getColor = False  
             getChar = True 
           elif getColor:
             color += line[i]
           elif getChar and line[i] == '<':
             ans += color_text(char,color.upper())
             getChar = False
             color = ''
             char = ''
             dontGet = True
           elif getChar:
             char += line[i]
           elif dontGet and line[i] == '>':
             dontGet = False
           elif not dontGet:
             ans+=line[i]
   return ans
#t = 'a[3]มิใช่ลิสต์ คืนค่ามิใช่print =มิใช่เปรียบเทียบ รักมิใช่ดวงดาวที่พราวแสง'
#print(color_text('This is red text', 'red'))
#print(color_text('This is green text', 'GreeN'))
#print(color_text('This is blue text', 'BLUE'))
#print(color_text('This is yellow text', 'yellow'))
#print(color_tag('<red>red text</>'))
#print(color_tag('<green>green text</>'))
#print(color_tag('<blue>blue text</>'))
#print('red text:', red('red text'), 'and normal text')
#print('green text:', green('green text'), 'and normal text')
#print('blue text:', blue('blue text'), 'and normal text')
#print('highlight text:', highlight('highlight text'), 'and normal text')
#print(highlight_words(t,['มิใช่']))	
#print(highlight_words(t,['ลิสต์']))
#print(highlight_words(t, []))
#w = ['print', 'ดาว', 'มิใช่']
#z = highlight_words(t, w)
#print(z)
#print(display_tag_file("มหาจุฬาลงกรณ์-tag.txt"))

6530200821: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display1.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 476, 'const': 620, 'code+const': 1096}
def red(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return RED + s + RESET
# ---------------------------------------------------
def green(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return GREEN + s + RESET
# ---------------------------------------------------
def blue(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return BLUE + s + RESET
# ---------------------------------------------------
def highlight(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return HIGHLIGHT + s + RESET
# ---------------------------------------------------
def color_text(s, color):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    if color.upper()=='RED':
      return RED + s + RESET
    if color.upper()=='BLUE':
      return BLUE + s + RESET
    if color.upper()=='GREEN':
      return GREEN + s + RESET
    else:
      return s
# ---------------------------------------------------
def color_tag(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    a = s.split('>')[0][1:].strip()
    br = s[-3:].strip()
    s = s.split('>')[1].split('<')[0].strip()
    if br == '</>':
        if a == 'red':
            s = red(s)
        elif a == 'blue':
            s = blue(s)
        elif a == 'green':
            s = green(s)
    return s
# ---------------------------------------------------
def highlight_words(s, words):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    for i in words:
        s = s.replace(i, highlight(i))
    return s
# ---------------------------------------------------
def display_tag_file(filename):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    file = open(filename, 'r', encoding='utf-8')
    for teelataew in file:
      teelataew = teelataew.replace('<red>', RED)
      teelataew = teelataew.replace('<blue>', BLUE)
      teelataew = teelataew.replace('<green>', GREEN)
      teelataew = teelataew.replace('</>', RESET)
      teelataew = teelataew.replace('\n', '')
      print(teelataew)
    file.close()

6530201421: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0
['\x1b[;103maBC\x1bc[0mde\x1b[;103mfg\x1b[0ma\x1b[;103mAbca\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display1.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 1756, 'const': 807, 'code+const': 2563}
def red(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    s=RED+s+RESET
    return s
# ---------------------------------------------------
def green(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    s=GREEN+s+RESET
    return s
# ---------------------------------------------------
def blue(s):
    s=BLUE+s+RESET
    return s
# ---------------------------------------------------
def highlight(s):
    s=HIGHLIGHT+s+RESET
    return s
# ---------------------------------------------------
def color_text(s,color):
    color=color.lower()
    if color=="red":
        return RED+s+RESET
    elif color=="green":
        return GREEN+s+RESET
    elif color=="blue":
        return BLUE+s+RESET
    else:
        return s
# ---------------------------------------------------
def color_tag(s):
    Front1=s.find("<")
    Front2=s.find(">")
    BackEnd=s.find("</>")
    Color=s[Front1+1:Front2]
    a=s[Front2+1:BackEnd]
    if Color=="red":
        s= RED+a+RESET  
    elif Color=="blue":
        s= BLUE+a+RESET 
    elif Color=="green":
        s= GREEN+a+RESET
    return s
# ---------------------------------------------------
def highlight_words(s, words):
    if words==[]:
        return s
    else:
        for i in range(len(words)):
            Position=s.find(words[i])
            t=s.lower()
            while Position!=-1:
                t=t[0:Position]+HIGHLIGHT+s[Position:Position+len(words[i])]+RESET+t[Position+len(words[i]):]
                s=s[0:Position]+HIGHLIGHT+s[Position:Position+len(words[i])]+RESET+s[Position+len(words[i]):] #มีเพื่อให้เป็นแบบการก๊อป
                Position=t.find(words[i],Position+len(HIGHLIGHT)+len(words[i]))
        return t
# ---------------------------------------------------
def display_tag_file(filename):
    Bonus="NO" #ตามชื่อเลยคือเพื่อ bonus
    Checker="NO" #เป็นตัวเช็คสำหรับ bonus ว่าถ้ามันมีพวกการเปลี่ยนสีแล้วยังแต่ต้องทำควบคู่กับ line.find("<")!=-1 เพราะอาจมีกรณีที่ไม่เปลี่ยนสีเลยได้
    Gun="NO"
    No_Bonus="NO" #เป็นของตัวหลอกที่มีโอกาสเจอทำให้ checker ไปทำงานเพราะมันจะไปเข้าโบนัส สัมพันธ์กับตัวแปร Gun จากการ debug
    fr=open(filename,"r",encoding="utf-8")
    line = fr.readline().strip()
    while len(line)!=0 or line=="\n": #loop สำหรับการอ่านไฟล์
        line=line.strip()
        BackEnd=line.find("</>")
        while BackEnd!=-1 or (Bonus=="YES" and len(line)!=0): #loop สำหรับการเปลี่ยนสียังไม่หมด
            if Bonus=="YES": #กรณีโบนัสของสมมติบรรทัด 1 ลากยาวมาบรรทัด 2 นี้คือบรรทัด 2
                Bonus="NO" #ทำการ default bonus
                BFront1=Previous.find("<")
                BFront2=Previous.find(">")
                BColor=Previous[BFront1+1:BFront2]
                line="<"+BColor+">"+line
                BackEnd=line.find("</>",BackEnd+1)
            if BackEnd!=-1 and Gun=="NO": #พอมันมี bonus เลยเป็นแบบนี้เพราะอาจมี bonus ที่พอหลุดออกมาเป็น -1 ได้
                Front1=line.find("<")
                Front2=line.find(">")
                Color=line[Front1+1:Front2]
                Word=line[Front2+1:BackEnd]
                if Color=="red":
                    line= line[:Front1]+RED+Word+RESET+line[BackEnd+3:]
                    Checker="YES"
                elif Color=="blue":
                    line=line[:Front1]+BLUE+Word+RESET+line[BackEnd+3:]
                    Checker="YES"
                elif Color=="green":
                    line= line[:Front1]+GREEN+Word+RESET+line[BackEnd+3:]
                    Checker="YES"
                elif Color not in ["red","blue","green"]:
                    Gun="OK"
                    Checker="YES"
                    No_Bonus="YES"
                BackEnd=line.find("</>")
                if Gun=="OK":
                    LastBackEnd=BackEnd
                    BackEnd=line.find("</>",BackEnd+1)
            elif BackEnd!=-1 and Gun=="OK": #กรณีหลอกแล้วยังมีต่อ
                Gun="NO"
                Front1=line.find("<",LastBackEnd+len("</>")) #
                Front2=line.find(">",LastBackEnd+len("</>")) #
                Color=line[Front1+1:Front2]
                Word=line[Front2+1:BackEnd]
                if Color=="red":
                    line= line[:Front1]+RED+Word+RESET+line[BackEnd+3:]
                    Checker="YES"
                elif Color=="blue":
                    line=line[:Front1]+BLUE+Word+RESET+line[BackEnd+3:]
                    Checker="YES"
                elif Color=="green":
                    line= line[:Front1]+GREEN+Word+RESET+line[BackEnd+3:]
                    Checker="YES"
                elif Color not in ["red","blue","green"]:
                    Gun="OK"
                    Checker="YES"
                    No_Bonus="YES"
                BackEnd=line.find("</>",BackEnd+1)
                if Gun=="OK":
                    BackEnd=line.find("</>",BackEnd+1)
        Checker="NO"#####
        if BackEnd==-1 and Checker=="NO" and line.find("<")!=-1 and len(line)!=0 and No_Bonus!="YES": #ของสมมติบรรทัดที่ 1 ถ้ามันมีเจ้าสีแล้วไม่มีตัวปิดก็ต้องสร้างขึ้นมาไปต่อสุดท้ายแล้วก็ต้องเปลี่ยนสีให้เรียบแล้วเลย
            No_Bonus="NO"
            Bonus = "YES"
            line+="</>"
            Front1=line.find("<")
            Front2=line.find(">")
            BackEnd=line.find("</>")
            Color=line[Front1+1:Front2]
            Previous=line
            Word=line[Front2+1:BackEnd]
            if Color=="red":
                line= line[:Front1]+RED+Word+RESET+line[BackEnd+3:]
                Checker="YES"
            elif Color=="blue":
                line=line[:Front1]+BLUE+Word+RESET+line[BackEnd+3:]
                Checker="YES"
            elif Color=="green":
                line= line[:Front1]+GREEN+Word+RESET+line[BackEnd+3:]
                Checker="YES"
        print(line)
        Checker="NO"
        Gun="NO"
        No_Bonus="NO"
        line = fr.readline()
    fr.close()

6530202021: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display0.0
abcrrrpkk

defgggocr

xyzbbbabc

abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 636, 'const': 826, 'code+const': 1462}
def red(s):
  a='\033[;31m'+s+'\033[0m'
  return a                      
# ---------------------------------------------------
def green(s):
  a='\033[;32m'+s+'\033[0m'
  return a
# ---------------------------------------------------
def blue(s):
  a='\033[;34m'+s+'\033[0m'
  return a    
# ---------------------------------------------------
def highlight(s):
  a='\033[;103m'+s+'\033[0m'
  return a 
# ---------------------------------------------------
def color_text(s, color):
  color=color.lower()
  if color=='red':
    return red(s)
  elif color=='green':
    return green(s)
  elif color=='blue':
    return blue(s)   
  else:
    return s    
# ---------------------------------------------------
def color_tag(s):
  a1,a2,a3=s.split('<')
  s=a1+a2+a3
  b=s.split('>')
  b[1]=b[1][:-1]
  text=b[1]
  color=b[0]
  if color=='red':
      return red(text)
  elif color=='green':
    return green(text)
  elif color=='blue':
    return blue(text)  
# ---------------------------------------------------
def highlight_words(s, words):
  n=0
  if len(words)!=0:
    while n!=len(words):
      x=s.split(words[n])
      y=str('\033[;103m'+str(words[n])+'\033[0m').join(x)
      s=y
      n+=1
    return y
  else:
    return s
# ---------------------------------------------------
def display_tag_file(filename):
  f=open(filename, 'r', encoding='utf-8')
  for line in f:
    p=[]
    n=0
    if '</>' in line:
      a=line.split('</>')
      for e in a:
        if '<' in e:
          k=e.find('<')
          x=e[k:]+'</>'
          p.append(x)
      while n!=len(p):
        i=line.split(p[n])
        i=str(color_tag(p[n])).join(i)
        line=i
        n+=1
      print(i)     
    else:
      print(line)  
  f.close()

6530203721: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display0.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 2700, 'const': 867, 'code+const': 3567}
def red(s):
    red = '\033[;31m' + s + '\033[0m'
    return red
# ---------------------------------------------------
def green(s):
    green = '\033[;32m' + s + '\033[0m'
    return green
# ---------------------------------------------------
def blue(s):
    blue = '\033[;34m' + s + '\033[0m'
    return blue
# ---------------------------------------------------
def highlight(s):
    highlight = '\033[;103m' + s + '\033[0m'
    return highlight
# ---------------------------------------------------
def color_text(s, color):
    color = color.upper()
    if color == 'RED':
        return red(s)
    elif color == 'GREEN':
        return green(s)
    elif color == 'BLUE':
        return blue(s)
    else:
        return s
# ---------------------------------------------------
def color_tag(s):
    start = ''
    text = ''
    for i in s:
        start += i
        if i == '>':
            break
    text += s[len(start):-3]
    if start == '<red>':
        return red(text)
    elif start == '<green>':
        return green(text)
    elif start == '<blue>':
        return blue(text)
# ---------------------------------------------------
def highlight_words(s, words):
    data = s
    out = ''
    end = 0
    start = 0
    hili = 0
    nohili = 0
    c = []
    if len(words) != 0:
        for i in words:
            ns = s.split(i)
            end += len(highlight(i))
            for k in ns:
                out += k + highlight(i)
            s = out
            c.append(data.count(i))
        for i in range(len(words)):
            hili += ((len(highlight(words[i])) * c[i]))
            nohili += len(words[i]) * c[i]
        leng = len(data)
        start = hili + leng + (end - nohili)
#         print(out)
#         print('start:',start)
#         print('leng:',leng)
#         print('hili:',hili)
#         print('nohili:',nohili)
#         print('end:',end)
        return out[-start:-end]
    else:
        return s
# ---------------------------------------------------
def display_tag_file(filename):
    fn = open(filename, 'r', encoding='utf-8')
#     out = ''
#     c = 0
#     for i in fn:
#         start = i.find('<')
#         end = i.find('<',start+1)
#         text = i[start:end+3]
#         if start >= 0 and end >= 0:
#             out += i[:start] + str(color_tag(text)) + i[end+3:]
#         elif start == -1 and end == -1:
#             out += i
#     fn.close()
#     print(out)
    out = ''
    for i in fn:
        text = ''
        r = i.find('<red>')
        b = i.find('<blue>')
        g = i.find('<green>')
        end = i.find('</>')
        if b == -1 and r < g and r != -1:
            out += i[:r]
            text += i[r:end+3]
            out += str(color_tag(text)) + i[end+3:g]
            text = ''
            end = i.find('</>',g)
            text += i[g:end+3]
            out += str(color_tag(text)) + i[end+3:]
        elif b == -1 and r > g and g != -1:
            out += i[:g]
            text += i[g:end+3]
            out += str(color_tag(text)) + i[end+3:r]
            text = ''
            end = i.find('</>',r)
            text += i[r:end+3]
            out += str(color_tag(text)) + i[end+3:]
        elif g == -1 and r < b and r != -1:
            out += i[:r]
            text += i[r:end+3]
            out += str(color_tag(text)) + i[end+3:b]
            text = ''
            end = i.find('</>',b)
            text += i[b:end+3]
            out += str(color_tag(text)) + i[end+3:]
        elif g == -1 and b < r and b != -1:
            out += i[:b]
            text += i[b:end+3]
            out += str(color_tag(text)) + i[end+3:r]
            text = ''
            end = i.find('</>',r)
            text += i[r:end+3]
            out += str(color_tag(text)) + i[end+3:]
        elif r == -1 and g > b and b != -1:
           out += i[:b]
           text += i[b:end+3]
           out += str(color_tag(text)) + i[end+3:g]
           text = ''
           end = i.find('</>',g)
           text += i[g:end+3]
           out += str(color_tag(text)) + i[end+3:]
        elif r == -1 and b > g and g != -1:
           out += i[:g]
           text += i[g:end+3]
           out += str(color_tag(text)) + i[end+3:b]
           text = ''
           end = i.find('</>',b)
           text += i[b:end+3]
           out += str(color_tag(text)) + i[end+3:]
        elif g == -1 and b == -1 and r >= 0:
           out += i[:r]
           text += i[r:end+3]
           out += str(color_tag(text)) + i[end+3:]
        elif g == -1 and r ==-1 and b >= 0:
           out += i[:b]
           text += i[b:end+3]
           out += str(color_tag(text)) + i[end+3:]
        elif r == -1 and b == -1 and g >= 0:
           out += i[:g]
           text += i[g:end+3]
           out += str(color_tag(text)) + i[end+3:]
        elif r != -1 and g != -1 and b != -1:
            if r < g < b :
                out += i[:r]
                text += i[r:end+3]
                out += str(color_tag(text)) + i[end+3:g]
                end = i.find('</>',g)
                text = ''
                text += i[g:end+3]
                out += str(color_tag(text)) + i[end+3:b]
                end = i.find('</>',b)
                text = ''
                text += i[b:end+3]
                out += str(color_tag(text)) + i[end+3:]
            elif g < b < r:
                out += i[:g]
                text += i[g:end+3]
                out += str(color_tag(text)) + i[end+3:b]
                end = i.find('</>',b)
                text = ''
                text += i[b:end+3]
                out += str(color_tag(text)) + i[end+3:r]
                end = i.find('</>',r)
                text = ''
                text += i[r:end+3]
                out += str(color_tag(text)) + i[end+3:]
            elif b < r < g:
                out += i[:b]
                text += i[b:end+3]
                out += str(color_tag(text)) + i[end+3:r]
                end = i.find('</>',r)
                text = ''
                text += i[r:end+3]
                out += str(color_tag(text)) + i[end+3:g]
                end = i.find('</>',g)
                text = ''
                text += i[g:end+3]
                out += str(color_tag(text)) + i[end+3:]
        else:
           out += i
#         print(r,g,b)
    fn.close()
    return out
# t = 'a[3]มิใช่ลิสต์ คืนค่ามิใช่print =มิใช่เปรียบเทียบ รักมิใช่ดวงดาวที่พราวแสง'

6530204321: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display1.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 598, 'const': 885, 'code+const': 1483}
def red(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return '\033[;31m'+s+'\033[0m'
# ---------------------------------------------------
def green(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return '\033[;32m'+s+'\033[0m'
# ---------------------------------------------------
def blue(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return '\033[;34m' +s+'\033[0m'
# ---------------------------------------------------
def highlight(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return '\033[;103m'+s+'\033[0m'
# ---------------------------------------------------
def color_text(s, color):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    if color.lower() in ['red','green','blue']:
        if color.lower() == 'red':
            return red(s)
        elif color.lower() == 'green':
            return green(s)
        elif color.lower() == 'blue':
            return blue(s)
    else:
        return '\033[0m'+s
# ---------------------------------------------------
def color_tag(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    x =s
    while '</>' in x:
        ind = x.find('<')
        ind2 = x.find('>',ind)
        ind3 = x.find('</>')
        color = x[ind+1:ind2].lower()
        if color == 'red':
            x = x[:ind] + '\033[;31m'+x[ind2+1:ind3]+'\033[0m'+x[ind3+3:]
        if color == 'blue':
            x = x[:ind] + '\033[;34m'+x[ind2+1:ind3]+'\033[0m'+x[ind3+3:]
        if color == 'green':
            x = x[:ind] + '\033[;32m'+x[ind2+1:ind3]+'\033[0m'+x[ind3+3:]
    return x
# ---------------------------------------------------
def highlight_words(s, words):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    x= s
    for i in words:
        x = x.replace(i.lower(),highlight(i.lower()))
        x = x.replace(i.upper(),highlight(i.upper()))
    return x
# ---------------------------------------------------
def display_tag_file(filename):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    s=''
    f =open(str(filename),'r',encoding = 'utf-8')
    for i in f:
        s+=color_tag(i)
    print(s)
    f.close()

6530205021: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display1.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 732, 'const': 668, 'code+const': 1400}
def red(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return RED + s + RESET
# ---------------------------------------------------
def green(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return GREEN + s + RESET
# ---------------------------------------------------
def blue(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return BLUE + s + RESET
# ---------------------------------------------------
def highlight(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return  HIGHLIGHT  + s + RESET
# ---------------------------------------------------
def color_text(s , color):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    c = color.lower()
    if c == "red" :
      return red(s)
    elif c == "green" :
      return green(s)
    elif c == 'blue' :
      return blue(s)
    else :
      return s
# ---------------------------------------------------
def color_tag(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    b = s.replace('<' , '>').split(">")
    if b[1] == 'red' :
      return color_text(b[2] , 'red')
    elif b[1] == 'green' :
      return color_text(b[2] , 'green')
    elif b[1] == 'blue' :
      return color_text(b[2] , 'blue') 
# ---------------------------------------------------
def highlight_words(s, words):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    if words == [] :
      return s
    for a in words :
      b = s.split(a)
      s = highlight(a).join(b)
    return s
# ---------------------------------------------------
def display_tag_file(filename):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    d = '' ; c = '' ; aread = ''
    a = open(filename, 'r', encoding='utf-8')
    for line in a :
      aread += line
    while aread.find("<") != -1 :
      aread = aread.split('<') 
      if aread[1][:3] == 'red' :
        c = aread[0]+color_tag('<'+aread[1]+'>'+'<'+aread[2][:2])+'<'.join(aread[2:])[2:]
      elif aread[1][:5] == 'green' :
        c = aread[0]+color_tag('<'+aread[1]+'>'+'<'+aread[2][:4])+'<'.join(aread[2:])[2:]
      elif aread[1][:4] == 'blue' :
        c = aread[0]+color_tag('<'+aread[1]+'>'+'<'+aread[2][:3])+'<'.join(aread[2:])[2:]
      aread = c
    d += c
    return print(d)

6530206621: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display0.0
abcrrrpkk

defgggocr

xyzbbbabc

abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 410, 'const': 343, 'code+const': 753}
def red(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return RED + s + RESET
# ---------------------------------------------------
def green(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return GREEN + s + RESET
# ---------------------------------------------------
def blue(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return BLUE + s + RESET
# ---------------------------------------------------
def highlight(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return HIGHLIGHT + s + RESET
# ---------------------------------------------------
def color_text(s, color):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    color = color.lower()
#     print(color)
    if color == "red":
        return red(s)
    elif color == "green":
        return green(s)
    elif color == "blue":
        return blue(s)
    else:
        return s
# ---------------------------------------------------
def color_tag(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    start1 = s.find("<")
    stop1 = s.find(">")
    start2 = s.find("<",start1 + 1)
    stop2 = s.find(">",stop1 + 1)
    color = s[start1+1:stop1]
    return s[0:start1] + color_text(s[stop1+1:start2],color) + s[stop2+1:]
# ---------------------------------------------------
def highlight_words(s, words):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
#    for i in range(len(s)):
#      if s[i:i+len(words)+1].lower == words.lower:            
#          s = s[0:i] + highlight(s[i:i+len(words)+1]) + s[i:i+len(words)+2:]
    for word in words:
        s = s.replace(word, highlight(word))
    return s
# ---------------------------------------------------
def display_tag_file(filename):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    fn = open(filename, 'r', encoding='utf-8')
    for line in fn:
        while "<" in line:
            line = color_tag(line)
        print(line)
    fn.close()
# display_tag_file('มหาจุฬาลงกรณ์-tag.txt')
#print(highlight_words("YES NO OK yes no ok Yes No Ok", ["yes"]))

6530207221: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display0.0
abcrrrpkk

defgggocr

xyzbbbabc

abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 470, 'const': 963, 'code+const': 1433}
def red(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    output = '\033[;31m'+str(s)+'\033[0m'
    return output
# ---------------------------------------------------
def green(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    output = '\033[;32m'+str(s)+'\033[0m'
    return output
# ---------------------------------------------------
def blue(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    output = '\033[;34m'+str(s)+'\033[0m'
    return output
# ---------------------------------------------------
def highlight(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    output = '\033[;103m'+str(s)+'\033[0m'
    return output
# ---------------------------------------------------
def color_text(s, color):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    color = color.lower()
    if color == 'red':
      return red(s)
    elif color == 'blue' :
      return blue(s)
    elif color == 'green':
      return green(s)
    else :
      return s
# ---------------------------------------------------
def color_tag(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    color = s[s.find('<')+1:s.find('>')]
    word = s[s.find('>')+1:s.find('/')-1]
    if color == 'red' :
      return red(word)
    elif color == 'green':
      return green(word)
    elif color == 'blue':
      return blue(word) 
# ---------------------------------------------------
def highlight_words(s, words):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    for word in words:
      s = s.replace(word,'\033[;103m'+ str(word)+'\033[0m')
    return s
# ---------------------------------------------------
def display_tag_file(filename):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    files = open(filename, 'r', encoding='utf-8')
    for line in files:
      line = line.replace('<red>', '\033[;31m')
      line = line.replace('<green>', '\033[;32m')
      line = line.replace('<blue>', '\033[;34m')
      line = line.replace('</>', '\033[0m')
      print(line)
    files.close()

6530208921: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display1.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 476, 'const': 952, 'code+const': 1428}
def red(s):
    return '\033[;31m'+s+'\033[0m'
# ---------------------------------------------------
def green(s):
    return '\033[;32m'+s+'\033[0m'
# ---------------------------------------------------
def blue(s):
    return '\033[;34m'+s+'\033[0m'
# ---------------------------------------------------
def highlight(s):
    return '\033[;103m'+s+'\033[0m'
# ---------------------------------------------------
def color_text(s, color):
    if color.lower() == 'red':
        return red(s)
    if color.lower() == 'green':
        return green(s)
    if color.lower() == 'blue':
        return blue(s)
    else: return s
# ---------------------------------------------------
def color_tag(s):
    k = s.find('>')
    if s[1:k] == 'red':
        return red(s[k+1:-3])
    if s[1:k] == 'green':
        return green(s[k+1:-3])
    if s[1:k] == 'blue':
        return blue(s[k+1:-3])
# ---------------------------------------------------
def highlight_words(s, words):
    for i in range(len(words)):
        s = s.replace(words[i],'\033[;103m'+words[i]+'\033[0m')
    return s
# ---------------------------------------------------
def display_tag_file(filename):
    s = ''
    x = open(filename, 'r', encoding='utf-8')
    for e in x:
        s += e
    s = s.replace('<red>','\033[;31m')
    s = s.replace('<green>','\033[;32m')
    s = s.replace('<blue>','\033[;34m')
    s = s.replace('</>','\033[0m')
    x.close()
    print (s)

6530209521: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display1.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 534, 'const': 479, 'code+const': 1013}
def red(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return RED + s + RESET
# ---------------------------------------------------
def green(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return GREEN + s + RESET
# ---------------------------------------------------
def blue(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return BLUE + s + RESET
# ---------------------------------------------------
def highlight(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return HIGHLIGHT + s + RESET
# ---------------------------------------------------
def color_text(s, color):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    color = color.lower()
    if color == 'red' :
      return red(s)
    if color == 'green' :
      return green(s)
    if color == 'blue' :
      return blue(s)
# ---------------------------------------------------
def color_tag(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return color_text(s[s.index(">")+1:s.index("<",s.index(">"))],s[1:s.index(">")])
# ---------------------------------------------------
def highlight_words(s, words):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    for word in words :
      i = 0
      w = ''
      while s.find(word,i) != -1 :
        w += s[i:s.find(word,i)]+highlight(word)
        i = s.find(word,i)+len(word)
      w += s[i:]
      s = w
    return w
# ---------------------------------------------------
def display_tag_file(filename):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    a = open(filename, 'r', encoding='utf-8')
    l=''
    for b in a:
      l += b
    w = ''
    i = 0
    while l.find('</>',i)!=-1 :
      tag = l[l.find('<',i):l.find('</>',i)+3]
      w += l[i:l.find('<',i)]+color_tag(tag)
      i = l.find('</>',i)+3
    w += l[i:]
    print(w)

6530210021: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display0.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 478, 'const': 339, 'code+const': 817}
def red(s):
    return RED + s + RESET
def green(s):
    return GREEN + s + RESET
def blue(s):
    return BLUE + s + RESET
def highlight(s):
    return HIGHLIGHT + s + RESET
def color_text(s, color):
    color = color.upper()
    if color == 'BLUE':
        return blue(s)
    elif color == 'RED':
        return red(s)
    elif color == 'GREEN':
        return green(s)
    else:
        return s
def color_tag(s):
    color = ''
    text = ''
    for e in s:
        if not e == '>':
            color += e
        elif e == '>':
            break
    color = color[color.find('<')+1:].upper()
    ind = s.find('>')
    for e in s[ind+1:]:
        if e != '<':
            text += e
        elif e == '<':
            break
    if color == 'RED':
        return red(text)
    elif color == 'GREEN':
        return green(text)
    elif color == 'BLUE':
        return blue(text)
    if color == 'RED':
        return red(text)
    elif color == 'GREEN':
        return green(text)
    elif color == 'BLUE':
        return blue(text)
def highlight_words(s, words):
    for ch in words:
        if ch in s:
          s = s.replace(ch,highlight(ch))
    return s
def display_tag_file(filename):
    pass

6530211721: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display0.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 402, 'const': 324, 'code+const': 726}
def red(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    col= RED + s + RESET
    return (col)
# ---------------------------------------------------
def green(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    col= GREEN + s + RESET
    return (col)
# ---------------------------------------------------
def blue(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    col= BLUE + s + RESET
    return (col)
# ---------------------------------------------------
def highlight(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    col= HIGHLIGHT + s + RESET
    return (col)
# ---------------------------------------------------
def color_text(s, color):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    if col== "Red":
      return (red(s))
    else:
      if col== "Green":
        return (green(s))
      else:
        if col== "Blue":
          return (blue(s))
# ---------------------------------------------------
def color_tag(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    position1= s.find('<',0)
    position2= s.find('>',position1+1)
    position3= s.find('<',position2+1)
    color_text= s[position1+1:position2:1]
    text= s[position2+1:position3:1]
    if color_text== 'Red':
      return (red(text))
    else:
      if color_text=='Blue':
        return (blue(text))
      else:
        if color_text=='Green':
          return (green(text))
        else:
          return text
# ---------------------------------------------------
def highlight_words(s, words):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    for i in range(len(words)):
      s= s.split(words[i])
      h= highlight(words[i])
      s= h.join(s)
    return (s)
# ---------------------------------------------------
def display_tag_file(filename):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    pass

6530212321: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display0.0
abcrrrpkk

defgggocr

xyzbbbabc

abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 814, 'const': 1229, 'code+const': 2043}
def red(s):
  # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
  w = '\033[;31m'
  for e in s :
      w += e
  w += '\033[0m'
  return w
# ---------------------------------------------------
def green(s):
  # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
  w = '\033[;32m'
  for e in s :
      w += e
  w += '\033[0m'
  return w
# ---------------------------------------------------
def blue(s):
  # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
  w = '\033[;34m'
  for e in s :
      w += e
  w += '\033[0m'
  return w
# ---------------------------------------------------
def highlight(s):
  # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
  w = '\033[;103m'
  for e in s :
      w += e
  w += '\033[0m'
  return w
# ---------------------------------------------------
def color_text(s, color):
  # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
  c = color.lower()
  if c == 'red' :
      w = '\033[;31m'
  elif c == 'blue' :
      w = '\033[;34m'
  elif c == 'green' :
      w = '\033[;32m'
  else :
      w = ''
  for e in s :
      w += e
  w += '\033[0m'
  return w
# ---------------------------------------------------
def color_tag(s):
  # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
  c = s.find('>')
  if c == 4 :
      w = '\033[;31m'
  elif c == 5 :
      w = '\033[;34m'
  else :
    w = '\033[;32m'
  stop = s.find('<',1)
  for e in s[c+1:stop:] :
      w += e
  w += '\033[0m'
  return w
# ---------------------------------------------------
def highlight_words(s, words):
  # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
  h = '\033[;103m' ; closeh = '\033[0m'
  if len(words) > 0 :
      for e in words :
          find = False
          c = s.find(e)
          if c != -1 :
              find = True
          while find :
              highlight = s[:c:] + h + e + closeh + s[c+len(e)::]
              find = False
              s = highlight
              c = s.find(e,len(s[:c:])+len(h)+1)
              if c != -1 :
                  find = True
      return s
  else :
      return s
# ---------------------------------------------------
def display_tag_file(filename):
  # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
  fin = open(filename, 'r', encoding='utf-8')
  r = '\033[;31m' ; b = '\033[;34m' ; g = '\033[;32m' ; reset = '\033[0m'
  for line in fin :
      s = ''
      o = line.find('<')
      while o != -1 :
          c = line.find('>')
          s += line[:o:]
          if c-o == 4 :
              s += r
          elif c-o == 5 :
              s += b
          else :
              s += g
          w = line.find('<',o+1)
          w2 = line.find('>',c+1)
          s += line[c+1:w:]
          s += reset + line[w2+1::]
          line = s
          o = line.find('<')
          s = ''
      print(line)
  fin.close()

6530213021: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display1.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 658, 'const': 600, 'code+const': 1258}
def red(s):
    return RED + s + RESET
# ---------------------------------------------------
def green(s):
    return GREEN + s + RESET
# ---------------------------------------------------
def blue(s):
    return BLUE + s + RESET
# ---------------------------------------------------
def highlight(s):
    return HIGHLIGHT + s + RESET
# ---------------------------------------------------
def color_text(s, color):
    color = color.lower()
    if color == "red":
        s = red(s)
    if color == "blue":
        s = blue(s)
    if color == "green":
        s = green(s)
    return s
# ---------------------------------------------------
def color_tag(s):
    a = s.find(">")
    color = s[1:a]
    s = s[1::]
    b = s.find("<")
    text = s[a:b]
    if color == "red":
        return red(text)
    if color == "green":
        return green(text)
    if color == "blue":
        return blue(text)
# ---------------------------------------------------
def highlight_words(s, words): 
    for e in words:
        s = s.replace(e, highlight(e))
    return s
# ---------------------------------------------------
def display_tag_file(filename):
    infile = open(filename, 'r', encoding='utf-8') 
    s = ""
    for line in infile:
        p = 0
        c = 0
        for e in line:
            if e == "<":
                c += 1/2
        for i in range(int(c)):
            a = line.find("<",p)
            b = line.find(">",p)
            c = line.find("<",a+1)
            d = line.find(">",b+1)
            color = line[a+1:b]
            text = line[b+1:c]
            if color == "red":
                line = line.replace(line[a:d+1], red(text))
            elif color == "green":
                line = line.replace(line[a:d+1], green(text))
            elif color == "blue":
                line = line.replace(line[a:d+1], blue(text))
            p = d
        s += line
    print(s)
    infile.close()

6530330721: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display0.0FileNotFoundError("No such file or directory: 'มหาจุฬาลงกรณ์-tag.txt'")
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 666, 'const': 1102, 'code+const': 1768}
def red(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
  RED = '\033[;31m'
  RESET = '\033[0m'
  for i in s :
    RED += i
  RED += RESET
  return RED
# ---------------------------------------------------
def green(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
  GREEN = '\033[;32m'
  RESET = '\033[0m'
  for i in s :
    GREEN += i
  GREEN += RESET
  return GREEN
# ---------------------------------------------------
def blue(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
  BLUE = '\033[;34m' 
  RESET = '\033[0m'
  for i in s :
    BLUE += i
  BLUE += RESET
  return BLUE
# ---------------------------------------------------
def highlight(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
  HIGHLIGHT = '\033[;103m'
  RESET = '\033[0m'
  for i in s :
    HIGHLIGHT += i
  HIGHLIGHT += RESET
  return HIGHLIGHT
# ---------------------------------------------------
def color_text(s, color):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
  ANS=''
  color = color.lower()
  if color == 'red':
      ANS = red(s) + RESET
  elif color == 'green':
      ANS = green(s) + RESET
  elif color == 'blue':
      ANS = blue(s) + RESET
  else :
      ANS = s
  return(ANS)
# ---------------------------------------------------
def color_tag(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    for i in s :
        if s[0:5] == '<red>':
            text = s[5:-3]
            ANS = RED+text+RESET
        elif s[0:7] == '<green>':
            text = s[7:-3]
            ANS = GREEN+text+RESET
        elif s[0:6] == '<blue>':
            text = s[6:-3]
            ANS = BLUE+text+RESET
    return(ANS)
# ---------------------------------------------------
def highlight_words(s, words):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    x=s
    if len(words)==1:
      x=s.replace(words[0],highlight(words[0]))
      return x
    else:
      for word in words:
        x=x.replace(word,highlight(word))
      return x
# ---------------------------------------------------
def display_tag_file(filename):
    RESET = '\033[0m'
    RED = '\033[;31m'
    GREEN = '\033[;32m'
    BLUE = '\033[;34m'
    HIGHLIGHT = '\033[;103m'
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    x=''
    ANS=''
    file=open('มหาจุฬาลงกรณ์-tag.txt', 'r', encoding='utf-8')
    for line in file:
      ANS=line
      ANS=ANS.replace('<red>',RED)
      ANS=ANS.replace('<blue>',BLUE)
      ANS=ANS.replace('<green>',GREEN)
      ANS=ANS.replace('</>',RESET)
      ANS=ANS.replace('\n','')
      print(ANS)
    YO=''
    return YO
# ---------------------------------------------------

6530398421: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display0.0FileNotFoundError("No such file or directory: 'มหาจุฬาลงกรณ์-tag.txt.lyrics'")
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 748, 'const': 676, 'code+const': 1424}
def red(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return RED+s+RESET
# ---------------------------------------------------
def green(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return GREEN+s+RESET
# ---------------------------------------------------
def blue(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return BLUE+s+RESET
# ---------------------------------------------------
def highlight(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return HIGHLIGHT+s+RESET
# ---------------------------------------------------
def color_text(s, color):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    x = ["RED","GREEN","BLUE"]
    y = [color.upper()]
    if y in x:
      if y == "RED":
        return red(s)
      if y == "GREEN":
        return green(s)
      if y == "BLUE":
        return blue(s)
      else:
        return s
# ---------------------------------------------------
def color_tag(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    y = s[1:6:1]
    if "red" in y:
      return red(s[5:len(s)-3:1])
    if "green" in y:
      return green(s[7:len(s)-3:1])
    if "blue" in y:
      return blue(s[6:len(s)-3:1])
# ---------------------------------------------------
def highlight_words(s, words):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    for j in range(len(words)):
      ans = ""
      x = s.find(words[j])
      y = len(words[j])
      if x != -1:
        i = 0
        while i < len(s):
          if i == x:
            ans += highlight(words[j])
            x = s.find(words[j],i+y)
            i += y
          else:
            ans += s[i]
            i += 1
      s = ans
    return s
# ---------------------------------------------------
def display_tag_file(filename):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    f = open('มหาจุฬาลงกรณ์-tag.txt.lyrics', 'r', encoding='utf-8')
    while(1):
      read = f.readline().strip()
      if(len(read)==0):
        break
      color = []
      a=-1
      i=0
      while i!=-1:
        i = read.find('<',a+1)
        k = read.find('>',a+1)
        j = read.find('>',k+1)
        a = j
        if i!=-1:
          color.append([i,j+1])
      result = ''
      last=0
      for e in color:
        result+=read[last:e[0]]
        result+=color_tag(read[e[0]:e[1]])
        last=e[1]
      result+=read[last:len(read)]
      print(result)

6531001421: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_10.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display1.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 434, 'const': 386, 'code+const': 820}
def red(s):
  return(RED+s+RESET)
def green(s):
  return(GREEN+s+RESET)
def blue(s):
  return(BLUE+s+RESET)
def highlight(s):
  return(HIGHLIGHT+s+RESET)
def color_text(s,color):
  color = color.upper() 
  color_changer = RESET
  if color == 'RED':
    color_changer = RED
  elif color == 'BLUE':
    color_changer = BLUE
  elif color == 'GREEN':
    color_changer = GREEN
  return(color_changer + s + RESET)
def color_tag(s):
  s = s.replace('<red>',RED)
  s = s.replace('<blue>',BLUE)
  s = s.replace('<green>',GREEN)
  s = s.replace('</>',RESET)
  return(s)
def highlight_words(s, words):
  for message in words:
    i = 0
    while i < (len(s)-len(message)):
      if s[i:i + len(message)].upper() == message.upper():
        s = s[:i+len(message)] + RESET + s[i+len(message):]
        s = s[:i] + HIGHLIGHT + s[i:]
        i += len(HIGHLIGHT)
      i += 1
  return(s)
def display_tag_file(filename):
  file = open(filename,'r',encoding='utf-8')
  print(color_tag(file.read()))

6531002021: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_21.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display1.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 768, 'const': 712, 'code+const': 1480}
def red(s):
    return '\033[;31m' + str(s) + '\033[0m'
# ---------------------------------------------------
def green(s):
    return '\033[;32m' + str(s) + '\033[0m'
# ---------------------------------------------------
def blue(s):
    return '\033[;34m' + str(s) + '\033[0m'
# ---------------------------------------------------
def highlight(s):
    return '\033[;103m' + str(s) + '\033[0m'
# ---------------------------------------------------
def color_text(s, color):
    color = color.lower()
    if color == 'red':
      return red(s)
    elif color == 'green':
      return green(s)
    elif color == 'blue':
      return blue(s)
    return s
def color_tag(s):
    ans = s
    x = s.find('</>')
    while x !=-1:
      x=ans.find('</>')
      r = ans.find('<red>')
      g = ans.find('<green>')
      b = ans.find('<blue>')
      if r!=-1:
        x = ans.find('</>',r)
        head = ans[:r]
        tail = ans[x+3:]
        body = red(ans[r+5:x])
        ans = head + body + tail
      elif b!=-1:
        x = ans.find('</>',b)
        head = ans[:b]
        tail = ans[x+3:]
        body = blue(ans[b+6:x])
        ans = head + body + tail
      elif g!=-1:
        x=ans.find('</>',g)
        head = ans[:g]
        tail = ans[x+3:]
        body = green(ans[g+7:x])
        ans = head + body + tail
      elif b==-1 and r==-1 and g==-1:
        break
    return ans
# ---------------------------------------------------
def highlight_words(s, words):
    for e in words:
      x = s.lower().find(e.lower())
      while x!=-1:
        hig = highlight(s[x:x+len(e)])
        h = s[:x]
        t = s[x+len(e):]
        s = h + hig + t
        x = s.lower().find(e.lower(),x+len(hig))
    return s
# ---------------------------------------------------
def display_tag_file(filename):
    mfile = open(filename, 'r', encoding='utf-8')
    ans = ''
    for line in mfile:
      ans += str(line) 
    ans = color_tag(ans)
    print(ans)
    mfile.close()

6531004321: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display0.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 346, 'const': 306, 'code+const': 652}
def red(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return RED + s + RESET
# ---------------------------------------------------
def green(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return GREEN + s + RESET
# ---------------------------------------------------
def blue(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return BLUE + s + RESET
# ---------------------------------------------------
def highlight(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return HIGHLIGHT + s + RESET
# ---------------------------------------------------
def color_text(s, color):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    if color.lower() == "red":
      return red(s)
    elif color.lower() == 'blue':
      return blue(s)
    elif color.lower() == 'green':
      return green(s)
    else:
      return s  
# ---------------------------------------------------
def color_tag(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    s = s.replace('<',' ').replace('>',' ').split()
    color = s.pop(0)
    s.pop()
    output = " ".join(s)
    if color == "red":
      return red(output)
    elif color == "blue":
      return blue(output)
    else:
      return green(output)
    return s
# ---------------------------------------------------
def highlight_words(s, words):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    for word in words:
      highlighted = highlight(word)
      s = s.split(word)
      s = highlighted.join(s)
    return s
# ---------------------------------------------------
def display_tag_file(filename):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    pass

6531005021: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display0.0FileNotFoundError("No such file or directory: 'มหาจุฬาลงกรณ์-tag.txt'")
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 514, 'const': 672, 'code+const': 1186}
def red(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return RED+s+RESET
# ---------------------------------------------------
def green(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return GREEN+s+RESET
# ---------------------------------------------------
def blue(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return BLUE+s+RESET
# ---------------------------------------------------
def highlight(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return HIGHLIGHT+s+RESET
# ---------------------------------------------------
def color_text(s, color):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    if color.lower() == 'red':
        return red(s)
    if color.lower() == 'green':
        return green(s)
    if color.lower() == 'blue':
        return blue(s)
    if color.lower() not in ['red','green','blue']:
        return s
# ---------------------------------------------------
def color_tag(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    s = s.replace("</>", RESET)
    if s.find("<red>") >=0:
        return s.replace("<red>", RED)
    if s.find("<green>") >=0:
        return s.replace("<green>", GREEN)
    if s.find("<blue>") >=0:
        return s.replace("<blue>", BLUE)
# ---------------------------------------------------
def highlight_words(s, words):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    i=0;x=-1;y=s
    S=s.upper()
    while i < len(words):
        W=words[i].upper()        
        x=S.find(W)       
        if x >=0:
            wrd=s[x:x+len(W)]            
            wrd2=HIGHLIGHT+wrd+RESET
            y=y.replace(wrd,wrd2)
        i+=1
    return y
# ---------------------------------------------------
def display_tag_file(filename):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    newline=''
    infile=open('มหาจุฬาลงกรณ์-tag.txt', 'r', encoding='utf-8')
    for line in infile:
        line=line.replace("</>", RESET)
        line=line.replace("<red>", RED)
        line=line.replace("<green>", GREEN)
        line=line.replace("<blue>", BLUE)
        newline=newline+line
    infile.close()
    return newline

6531008921: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display1.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 498, 'const': 1109, 'code+const': 1607}
def red(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    a = '\033[;31m' + s + '\033[0m'
    return a
# ---------------------------------------------------
def green(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    b = '\033[;32m' + s + '\033[0m'
    return b
# ---------------------------------------------------
def blue(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    c = '\033[;34m' + s + '\033[0m'
    return c
# ---------------------------------------------------
def highlight(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    d = '\033[;103m' + s + '\033[0m'
    return d
# ---------------------------------------------------
def color_text(s, color):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    cl = color.lower()
    if cl == 'red':l = red(s)
    elif cl == 'green':l = green(s)
    elif cl == 'blue':l = blue(s)
    else:l = s        
    return l
# ---------------------------------------------------
def color_tag(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    if '<red>' in s:
      a = s.replace('<red>','\033[;31m')
    if '<green>' in s:
      a = s.replace('<green>','\033[;32m')
    if '<blue>' in s:
      a = s.replace('<brue>','\033[;34m')
    b = a.replace('</>','\033[0m')
    return b
# ---------------------------------------------------
def highlight_words(s, words):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    if words != []:
        for i in words:
            a = '\033[;103m' + i + '\033[0m'
            b = s.replace(i,a)
            s = b
    else: b = s
    return b
# ---------------------------------------------------
def display_tag_file(filename):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    file = open(filename,'r', encoding='utf-8')
    for line in file:
      if '<red>' in line:
        a = line.replace('<red>','\033[;31m')
        b = a.replace('</>','\033[0m')
        line = b
      if '<green>' in line:
        c = line.replace('<green>','\033[;32m')
        d = c.replace('</>','\033[0m')
        line = d
      if '<blue>' in line:
        e = line.replace('<blue>','\033[;34m')
        f = e.replace('</>','\033[0m')
        line = f
      print(line,end='')
    file.close()

6531009521: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_10.0NameError("name 'hightlights' is not defined")
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0NameError("name 'hightlights' is not defined")
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display0.0
abcrrrpkk

defn>gggocr

xyz>bbbabc

abcrrrpfn&gt;gggorrz>bbbabc
[]
bytecount: {'code': 592, 'const': 550, 'code+const': 1142}
def red(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
   return RED+s+RESET
# ---------------------------------------------------
def green(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return GREEN+s+RESET
# ---------------------------------------------------
def blue(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return BLUE+s+RESET
# ---------------------------------------------------
def highlight(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return HIGHLIGHT+s+RESET
# ---------------------------------------------------
def color_text(s, color):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    if  color.lower() == 'red':
      return red(s)
    if  color.lower() == 'blue':
      return blue(s)
    if  color.lower() == 'green':
      return green(s)
    if  color.lower() != 'red' and color.lower() != 'blue' and color.lower() != 'green':
      return s       
# ---------------------------------------------------
def color_tag(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    if '<red>' and '</>' in s:
      a=s[5:-3]
      return red(a)
    if '<blue>' and '</>' in s:
      a=s[6:-3]
      return blue(a)
    if '<green>' and '</>' in s:
      a=s[7:-3]
      return green(a)
# ---------------------------------------------------
def highlight_words(s, words):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    for i in words:
      c=s.find(i)
      while c != -1 :
        s=s[0:c]+hightlights(s[c:c+len(i)])+s[c+len(i):]
        c=s.find(i,c+len(HIGHLIGHT)+len(RESET)+1)
    return s
# ---------------------------------------------------
def display_tag_file(filename):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    file=open(filename, 'r', encoding='utf-8')
    for i in file:
      c=i.find('<')
      d=i.find('</>')
      while c != -1:
        i=i[0:c]+color_tag(i[c:d+3])+i[d+3:]
        c=i.find('<',)
        d=i.find('</>',)
      print(i)
    file.close()

6531010021: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display0.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 714, 'const': 620, 'code+const': 1334}
def green(s):
  result = GREEN + s + RESET
  return result
# ---------------------------------------------------
def red(s):
  result = RED + s + RESET
  return result
# ---------------------------------------------------
def blue(s):
    result = BLUE + s + RESET
    return result
# ---------------------------------------------------
def highlight(s):
    result = HIGHLIGHT + s + RESET
    return result
# ---------------------------------------------------
def color_text(s, color):
    d = color.lower()
    if d == 'red':
        return red(s)
    elif d == 'blue' :
        return blue(s)
    elif d == 'green' :
        return green(s)
    else :
        return s
def color_tag(s):
    if '<red>' in s :
        c = s.find('<red>')
        v = s.find('</>')
        return red(s[c+5:v])
    if '<blue>' in s :
        b = s.find('<blue>')
        q = s.find('</>')
        return blue(s[b+6:q])
    if '<green>' in s :
        p = s.find('<green>')
        u = s.find('</>')
        return green(s[p+7:u])
# ---------------------------------------------------
def highlight_words(s, words):
    for w in words:
      s = s.replace(w, highlight(w))
    return s
# ---------------------------------------------------
def display_tag_file(filename):
    # read text file
    f = open(filename, 'r', encoding='utf-8')
    s = f.read()
    for i in ['<red>', '<blue>', '<green>']:
      while s.find(i)!=-1:
        ind = s.find(i)
        left = s[:ind]
        right = s[s[ind:].find('</>')+3+ind:]
        text = ''
        if i=='<red>':
          text += s[ind+5:s[ind:].find('</>')+ind]
        elif i=='<blue>':
          text += s[ind+6:s[ind:].find('</>')+ind]
        else:
           text += s[ind+7:s[ind:].find('</>')+ind]
        middle = ''
        if i=='<red>':
          middle = red(text)
        elif i=='<blue>':
          middle = blue(text)
        else:
          middle = green(text)
        s = left + middle + right
    return s

6531011721: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display1.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 820, 'const': 592, 'code+const': 1412}
def red(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    s = RED+s+RESET
    return s
# ---------------------------------------------------
def green(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    s = GREEN+s+RESET
    return s
# ---------------------------------------------------
def blue(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    s = BLUE+s+RESET
    return s
# ---------------------------------------------------
def highlight(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    s = HIGHLIGHT+s+RESET
    return s
# ---------------------------------------------------
def color_text(s, color):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    if color.lower() == "red": return red(s)
    elif color.lower() == "blue": return blue(s)
    elif color.lower() == "green": return green(s)
    else: return s
# ---------------------------------------------------
def color_tag(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    o_tag = s.find("<")
    c_tag = s.find(">", o_tag)
    color = s[o_tag+1:c_tag]
    c = s.find("</>", c_tag+1)
    if color == 'red': return red(s[c_tag+1:c])
    elif color == 'blue': return blue(s[c_tag+1:c])
    elif color == 'green': return green(s[c_tag+1:c])
# ---------------------------------------------------
def highlight_words(s, words):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    for w in words:
      idx = []; i = s.find(w); idx.append(i)
      while i!=-1:
        i = s.find(w, i+len(w))
        if i==-1: break
        idx.append(i)
      n = len(highlight(w))
      for e in range(len(idx)):
        r = idx[e]+e*n
        s = s[:r-(e*len(w))]+highlight(w)+s[r-(e*len(w))+len(w):]
    return s
# ---------------------------------------------------
def display_tag_file(filename):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    fl = open(filename, 'r', encoding='utf-8')
    f = fl.read()
    i = f.find("\n")
    line = f[:i]
    print(line_tag(line))
    while i!=-1:
      k = i
      i = f.find("\n", i+2)
      if i==-1: line = f[k+1:]
      else: line = f[k+1:i]
      print(line_tag(line))
def line_tag(s):
  i = s.find("<")
  while i!=-1:
    f = s.find("</>",i)
    tag = s[i:f+3]
    s = s[:i]+color_tag(tag)+s[f+3:]
    i = s.find("<",f)
  return s

6531013021: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display1.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 676, 'const': 425, 'code+const': 1101}
def red(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return RED+s+RESET
# ---------------------------------------------------
def green(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return GREEN+s+RESET
# ---------------------------------------------------
def blue(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return BLUE+s+RESET
# ---------------------------------------------------
def highlight(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return HIGHLIGHT+s+RESET
# ---------------------------------------------------
def color_text(s, color):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    if (color.lower() in ['red', 'blue', 'green']):
      return globals()[color.upper()]+s+RESET
    else: return s
# ---------------------------------------------------
def color_tag(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    tag = s.find("<")
    c_tag = s.find(">", tag)
    color = s[tag+1:c_tag]
    close = s.find("</>", c_tag+1)
    return globals()[color.upper()]+s[c_tag+1:close]+RESET
# ---------------------------------------------------
def highlight_words(s, words):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    for w in words:
      i = s.find(w)
      s = s[:i]+HIGHLIGHT+s[i:i+len(w)]+RESET+s[i+len(w):]
      while i!=-1:
        i = s.find(w, i+len(HIGHLIGHT)+len(w)+len(RESET))
        if i==-1: break
        s = s[:i]+HIGHLIGHT+s[i:i+len(w)]+RESET+s[i+len(w):]
    return s
# ---------------------------------------------------
def display_tag_file(filename):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    f = open(filename, 'r', encoding='utf-8')
    for n in f.readlines():
      s = n.find("<"); e = n.find("</>", s)
      if s!=-1:
        tag = n[s:e+3]
        n = n[:s]+color_tag(tag)+n[e+3:]
        while s!=-1:
          s = n.find("<", e+3); e = n.find("</>", s)
          if s==-1: break
          tag = n[s:e+3]
          n = n[:s]+color_tag(tag)+n[e+3:]
      print(n, end="")

6531015221: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display0.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 322, 'const': 879, 'code+const': 1201}
def red(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
  return '\033[;31m'+s+'\033[0m'
# ---------------------------------------------------
def green(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
  return '\033[;32m'+s+'\033[0m'
# ---------------------------------------------------
def blue(s):
   # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
  return '\033[;34m'+s+'\033[0m' 
# ---------------------------------------------------
def highlight(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
  return '\033[;103m'+s+'\033[0m' 
# ---------------------------------------------------
def color_text(s, color):
  color=color.lower()
  if color=='red':
    return '\033[;31m'+s+'\033[0m'
  elif color=='green':
    return '\033[;32m'+s+'\033[0m'
  elif color=='blue':
    return '\033[;34m'+s+'\033[0m'
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
# ---------------------------------------------------
def color_tag(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
  s = s.replace("</>", "\033[0m")
  s = s.replace("<red>", "\033[;31m")
  s = s.replace("<green>", "\033[;32m")
  s = s.replace("<blue>", "\033[;34m")
  return s
# ---------------------------------------------------
def highlight_words(s, words):
  # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
  for i in words:
    s=s.replace(i,'\033[;103m'+i+'\033[0m')
  return s   
# ---------------------------------------------------
def display_tag_file(filename):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
  ans = ""
  f = open(filename, "r")
  for x in f:
    x = color_tag(x)
    ans += x
  return ans

6531017521: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display1.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 798, 'const': 1665, 'code+const': 2463}
def red(s):
    return RED+s+RESET
# ---------------------------------------------------
def green(s):
    return GREEN+s+RESET
# ---------------------------------------------------
def blue(s):
    return BLUE+s+RESET
# ---------------------------------------------------
def highlight(s):
    return HIGHLIGHT+s+RESET
# ---------------------------------------------------
def color_text(s, color):
    if color.upper() == 'RED':
      return red(s)
    if color.upper() == 'GREEN':
      return green(s)
    if color.upper() == 'BLUE':
      return blue(s)
    return s
# ---------------------------------------------------
def color_tag(s):
    c1 = s.find('>')
    o2 = s.find('<',c1)
    return color_text(s[c1+1:o2],s[1:c1])
# ---------------------------------------------------
def highlight_words(s, words):
    for w in words:
      i = -1
      while True:
        i = s.find(w,i+1)
        if i == -1 :
          break
        m = highlight(s[i:i+len(w)])
        s = s[:i]+m+s[i+len(w):]
        i += len(m)
    return s
# ---------------------------------------------------
def display_tag_file(filename):
    fin = open(filename,'r',encoding='utf-8')
    for line in fin:
      i = 0
      t = line
      while i < len(t) :
        if t[i] == '<' :
          en = t.find('</>',i)+3
          m = color_tag(t[i:en])
          t = t[:i]+m+t[en:]
          i += len(m)
        else :
          i += 1
      print(t,end="")
def main() : # อันนี้ไม่เกี่ยว แค่ลองทดสอบ
    print('red text:', red('red text'), 'and normal text')
    print('green text:', green('green text'), 'and normal text')
    print('blue text:', blue('blue text'), 'and normal text')
    print('highlight text:', highlight('highlight text'), 'and normal text')
    print(color_text('This is red text', 'red'))
    print(color_text('This is green text', 'GreeN'))
    print(color_text('This is blue text', 'BLUE'))
    print(color_text('This is yellow text', 'yellow'))
    print(color_tag('<red>red text</>'))
    print(color_tag('<green>green text</>'))
    print(color_tag('<blue>blue text</>'))
    t = 'a[3]มิใช่ลิสต์ คืนค่ามิใช่print =มิใช่เปรียบเทียบ รักมิใช่ดวงดาวที่พราวแสง'
    print(highlight_words(t,['มิใช่']))
    print(highlight_words(t,['ลิสต์']))
    print(highlight_words(t, []))
    w = ['print', 'ดาว', 'มิใช่']
    z = highlight_words(t, w)
    print(z)
    display_tag_file('มหาจุฬาลงกรณ์-tag.txt')

6531019821: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display1.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 340, 'const': 808, 'code+const': 1148}
def red(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return '\033[;31m' + s + '\033[0m'
# ---------------------------------------------------
def green(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return '\033[;32m' + s + '\033[0m'
# ---------------------------------------------------
def blue(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return '\033[;34m' + s + '\033[0m'
# ---------------------------------------------------
def highlight(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return '\033[;103m' + s + '\033[0m'
# ---------------------------------------------------
def color_text(s, color):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    color = color.lower()
    if color == 'red':
        return red(s)
    elif color == 'green':
        return green(s)
    elif color == 'blue':
        return blue(s)
    elif color == 'highlight':
        return highlight(s)
    else:
        return s
# ---------------------------------------------------
def color_tag(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    new_text = s.replace('<red>', '\033[;31m').replace('<green>', '\033[;32m').replace('<blue>', '\033[;34m').replace('</>' , '\033[0m')
    return new_text
# ---------------------------------------------------
def highlight_words(s, words):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    for word in words:
        s = s.replace(word , highlight(word))
    return s
# ---------------------------------------------------
def display_tag_file(filename):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    file1 = open(str(filename) , 'r', encoding='utf-8')
    for line in file1:
      print(color_tag(line), end = '')
    file1.close()

6531020321: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display1.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 446, 'const': 532, 'code+const': 978}
def red(s):
  return RED+s+RESET
# ---------------------------------------------------
def green(s):
  return GREEN+s+RESET
# ---------------------------------------------------
def blue(s):
  return BLUE+s+RESET
# ---------------------------------------------------
def highlight(s):
  return HIGHLIGHT+s+RESET
# ---------------------------------------------------
def color_text(s, color):
  c = color.upper()
  if c == 'RED':
    return red(s)
  elif c == 'BLUE':
    return blue(s)
  elif c == 'GREEN':
    return green(s)
  else:
    return s
# ---------------------------------------------------
def color_tag(s):
  if '<red>' in s:
    s = s.replace('<red>', RED)
  elif '<blue>' in s:
    s = s.replace('<blue>', BLUE)
  elif '<green>' in s:
    s = s.replace('<green>', GREEN)
  s = s.replace('</>', RESET)
  return s
# ---------------------------------------------------
def highlight_words(s, words):
  for i in range(len(words)):
    s = s.split(words[i])
    s = highlight(words[i]).join(s)
  return s
# ---------------------------------------------------
def display_tag_file(filename):
  file = open(filename, 'r', encoding='utf-8')
  for line in file:
    if '<red>' in line:
      line = line.replace('<red>', RED)
    if '<blue>' in line:
      line = line.replace('<blue>', BLUE)
    if '<green>' in line:
      line = line.replace('<green>', GREEN)
    line = line.replace('</>', RESET)
    print(line, end='')
  file.close()
# ---------------------------------------------------

6531021021: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display0.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 342, 'const': 308, 'code+const': 650}
def red(s):
  return RED+s+RESET
# ---------------------------------------------------
def green(s):
  return GREEN+s+RESET
# ---------------------------------------------------
def blue(s):
  return BLUE+s+RESET
# ---------------------------------------------------
def highlight(s):
  return HIGHLIGHT+s+RESET
# ---------------------------------------------------
def color_text(s, color):
  if color.lower() == 'red':
    return red(s)
  elif color.lower() == 'blue' :
    return blue(s)
  elif color.lower() == 'green' :
    return green(s)
  else :
    return s
# ---------------------------------------------------
def color_tag(s):
  if  "<red>" in s :
    s = s[5:-3]
    return red(s)
  elif "<blue>" in s :
    s = s[6:-3]
    return blue(s)
  elif "<green>" in s :
    s = s[7:-3]
    return green(s)
  else :
    pass
# ---------------------------------------------------
def highlight_words(s, words):
  for i in range(len(words)):
    s = s.replace(words[i],highlight(words[i]))
  return s
# ---------------------------------------------------
def display_tag_file(filename):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    pass

6531022621: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display1.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 320, 'const': 484, 'code+const': 804}
def red(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return "{}{}{}".format(RED, s, RESET)
# ---------------------------------------------------
def green(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return "{}{}{}".format(GREEN, s, RESET)
# ---------------------------------------------------
def blue(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return "{}{}{}".format(BLUE, s, RESET)
# ---------------------------------------------------
def highlight(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return "{}{}{}".format(HIGHLIGHT, s, RESET)
# ---------------------------------------------------
def color_text(s, color):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    color = color.lower()
    if color == 'red':
        return red(s)
    elif color == 'green':
        return green(s)
    elif color == 'blue':
        return blue(s)
    else:
        return s
# ---------------------------------------------------
def color_tag(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return s.replace('<red>', RED).replace('<green>', GREEN).replace('<blue>', BLUE).replace('</>', RESET)
# ---------------------------------------------------
def highlight_words(s, words):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    for word in words:
        s = s.replace(word, highlight(word))
    return s
# ---------------------------------------------------
def display_tag_file(filename):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    with open(filename, 'r', encoding='utf-8') as f:
        s = f.read()
        print(color_tag(s))

6531023221: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_21.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display1.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 658, 'const': 479, 'code+const': 1137}
def red(s):
    return RED + s + RESET
# ---------------------------------------------------
def green(s):
    return GREEN + s + RESET
# ---------------------------------------------------
def blue(s):
    return BLUE + s + RESET
# ---------------------------------------------------
def highlight(s):
    return HIGHLIGHT + s + RESET
# ---------------------------------------------------
def color_text(s, color):
    color = color.lower()
    if color=="red" : return RED + s + RESET
    if color=="green" : return GREEN + s + RESET
    if color=="blue" : return BLUE + s + RESET
    return s
# ---------------------------------------------------
def color_tag(s):
    q = s.find('>')
    x = s[1:q]
    s = s[q+1:-3]
    return color_text(s, x)  
# ---------------------------------------------------
def highlight_words(s, words):
    ## -- BONUS -- สามารถ highlight ได้โดยไม่สนว่าเป็นตัวพิมพ์เล็กหรือตัวพิมพ์ใหญ่
    for Txt in words :
        Txt2 = Txt.lower()
        s2 = s.lower()
        x = s2.split(Txt2)
        k = ''
        idx = 0
        for i in x[:-1] :
            k += s[idx:idx+len(i)] + HIGHLIGHT + s[idx+len(i):idx+len(i)+len(Txt)] + RESET
            idx += len(i)+len(Txt)
        s = k + s[idx:idx+len(x[-1])]
    return s
# ---------------------------------------------------
def display_tag_file(filename):
    ## -- BONUS -- สามารถแสดงสีให้ถูกต้องได้เมื่อ tag สี และ tag </> อยู่คนละบรรทัดกัน
    fin = open(filename, 'r', encoding='utf-8')
    TagLine = list()
    s = ''
    for line in fin : s += line
    for i in range(len(s)) :
        if s[i]=='<' or s[i]=='>' :
            TagLine += [i]
    idx = 0
    k = ''
    for x in range(0, len(TagLine), 4) :
        v = color_tag(s[TagLine[x]:TagLine[x+3]+1])
        k += s[idx:TagLine[x]] + v
        idx = TagLine[x+3]+1
    k += s[idx:]
    print(k)
    fin.close()
    return

6531024921: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_10.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display0.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 836, 'const': 644, 'code+const': 1480}
def red(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    red = RED+s+RESET
    return red
# ---------------------------------------------------
def green(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    green = GREEN+s+RESET
    return green
# ---------------------------------------------------
def blue(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    blue = BLUE+s+RESET
    return blue
# ---------------------------------------------------
def highlight(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    highlight = HIGHLIGHT+s+RESET
    return highlight
# ---------------------------------------------------
def color_text(s, color):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    b = color.lower()
    y = ""
    if b == "red" :
        y = red(s)
    elif b == "green" :
        y = green(s)
    elif b == "blue" :
        y = blue(s)
    else :
        y = s
    return y
# ---------------------------------------------------
def color_tag(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    a = ""
    b = ""
    for e in range(1,len(s)) :
        if  s[e] != ">" :
            a += s[e]
        else :
            break
    for i in range(len(a)+2,len(s)) :
        if s[i] != "<"  :
            b += s[i]
        else :
             break
    return color_text(b, a)
# ---------------------------------------------------
def highlight_words(s, words):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    b = []
    for e in range(len(words)) :
        b += [highlight(words[e])]
    for pp in range(len(words)) :
        g = 0
        f = []
        r = 0
        g = s.find(words[pp],r)
        while g != -1 :
            f += [g]
            r = g+len(words[pp])
            g = s.find(words[pp],r)
        o = ''
        u = 0
        for i in range(len(f)) :
            o += s[u:f[i]]+b[pp]
            u = f[i]+len(words[pp])
        o += s[u:]
    return o
# ---------------------------------------------------
def display_tag_file(filename):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    f = open(filename, 'r', encoding='utf-8')
    r = ""
    for line in f :
        c = []
        a = ""
        h = 0
        for i in range(len(line)) :    
            if line[i] == "<" :
                c += [line[h:i]]
                h = i+1
            elif line[i] == ">" :
                a = line[h:i].upper()
                h = i+1
                if a == "RED" :
                    c += RED
                elif a == "BLUE" :
                    c += BLUE
                elif a == "GREEN" :
                    c += GREEN
                elif a == "/" :
                    c += RESET
        c += [line[h:]]
        for e in range(len(c)) :
            r += c[e]
    return r
    f.close()

6531026121: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_10.0Time-out: 3s
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0Time-out: 3s
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display0.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 1314, 'const': 1313, 'code+const': 2627}
def red(s):
  # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
  return str(RED+s+RESET)
# ---------------------------------------------------
def green(s):
  # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
  return str(GREEN+s+RESET)
# ---------------------------------------------------
def blue(s):
  # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
  return str(BLUE+s+RESET)
# ---------------------------------------------------
def highlight(s):
  # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
  return str(HIGHLIGHT+s+RESET)
# ---------------------------------------------------
def color_text(s, color):
  # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
  color = color.lower()
  if color == "red":
    text = red(s)
  elif color == "green":
    text = green(s)
  elif color == "blue":
      text = blue(s)
  else:
      text = s
  return str(text)
# ---------------------------------------------------
def color_tag(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    text = ""
    if s[0] == "<" and s[1] == "r" and s[2] == "e" and s[3] == "d":
        n=5
        color = "red"
    elif s[0] == "<" and s[1] == "g" and s[2] == "r" and s[3] == "e" and s[4] == "e" and s[5] == "n":
        n=7
        color = "green"
    elif s[0] == "<" and s[1] == "b" and s[2] == "l" and s[3] == "u" and s[4] == "e":
        n=6
        color = "blue"
    for i in range(n, len(s)):
      if s[i] == "<" and s[i+1] == "/" and s[i+2] == ">":
        break
      else: 
        if color == "red":
          text += red(s[i])
        elif color == "green":
          text += green(s[i])
        elif color == "blue":
          text += blue(s[i])
    return text
# ---------------------------------------------------
def highlight_words(s, words):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    text = ""
    i=0
    while i < len(s):
      for w in words:
        check = 0
        t = ""
        for j in range(0, len(w)):
          if s[i+j] == w[j]:
            check += 1
          else:
            break
        if check == len(w):
          for j in range(len(w)):
            t += w[j]
          text += highlight(t)
          i += len(w)
      if check == 0:
        text += s[i]
        i+=1
    return text
# ---------------------------------------------------
def display_tag_file(filename):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    f = open(filename, "r", encoding='utf-8')
    color = "no"
    text = ""
    for s in f:
      i=0
      while i < len(s):
          if s[i] == "<" and s[i+1] == "r" and s[i+2] == "e" and s[i+3] == "d":
              i+=5
              color = "red"
          elif s[i] == "<" and s[i+1] == "g" and s[i+2] == "r" and s[i+3] == "e" and s[i+4] == "e" and s[i+5] == "n":
              i+=7
              color = "green"
          elif s[i] == "<" and s[i+1] == "b" and s[i+2] == "l" and s[i+3] == "u" and s[i+4] == "e":
              i+=6
              color = "blue"
          elif s[i] == "<" and s[i+1] == "/" and s[i+2] == ">":
              i+=3
              color = "no"
          if color == "red":
              text += red(s[i])
          elif color == "green":
              text += green(s[i])
          elif color == "blue":
              text += blue(s[i])
          elif color == "no":
              text += s[i]
          i+=1
    return text

6531027821: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_21.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display1.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 1048, 'const': 541, 'code+const': 1589}
def red(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return RED+s+RESET
# ---------------------------------------------------
def green(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return GREEN+s+RESET
# ---------------------------------------------------
def blue(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return BLUE+s+RESET
# ---------------------------------------------------
def highlight(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return HIGHLIGHT+s+RESET
# ---------------------------------------------------
def color_text(s, color):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    color = color.lower()
    if color=='red': return red(s)
    elif color=='green': return green(s)
    elif color=='blue': return blue(s)
    else: return s
# ---------------------------------------------------
def color_tag(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    c = ""
    t = ""
    i = 0
    while i < len(s):
      if c == "" and s[i]=='<':
        i+=1
        while(s[i]!='>'):
          c+=s[i]
          i+=1
      elif s[i]=='<':
        break
      else:
        t+=s[i]
      i+=1
    return color_text(t,c)
# ---------------------------------------------------
def highlight_words(s, words):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    for w in words:
      now = 0
      while (w.lower() in s[now:].lower()):
        idx = s[now:].lower().index(w.lower())+now
        now = len(s[:idx]+HIGHLIGHT+s[idx:idx+len(w)]+RESET)+1
        s=s[:idx]+HIGHLIGHT+s[idx:idx+len(w)]+RESET+s[idx+len(w):]
    return s
# ---------------------------------------------------
def display_tag_file(filename):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    f = open(filename, 'r', encoding='utf-8')
    ch = ""
    for l in f:
      now = 0
      if ch != "":
        if '<' in l:
          idx1 = l.index('<')
          if ch == 'r':
            l=RED+l[:idx1]+RESET+l[idx1+3:]
          elif ch =='b':
            l=BLUE+l[:idx1]+RESET+l[idx1+3:]
          else:
            l=GREEN+l[:idx1]+RESET+l[idx1+3:]
          now = idx1+1
          ch=""
        else:
          if ch == 'r':
            print(RED+l+RESET)
          elif ch =='b':
            print(BLUE+l+RESET)
          else:
            print(GREEN+l+RESET)
          continue
      while '<' in l[now:] and ch == "":
        idx = l[now:].index('<')+now
        if '<' in l[idx+1:]:
          idx1 = l[idx+1:].index('<')+3+idx+1
          le = len(l[:idx]+color_tag(l[idx:idx1]))
          l=l[:idx]+color_tag(l[idx:idx1])+l[idx1:]
          now = le+1
        else:
          ch = l[idx+1]
          l=l[:idx]+color_tag(l[idx:]+'</>')
      print(l,end='')
    f.close()
    return

6531028421: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display1.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 802, 'const': 1677, 'code+const': 2479}
def red(s):
    return RED + s + RESET
# ---------------------------------------------------
def green(s):
    return GREEN + s + RESET
# ---------------------------------------------------
def blue(s):
    return BLUE + s + RESET
# ---------------------------------------------------
def highlight(s):
    return HIGHLIGHT + s + RESET
# ---------------------------------------------------
def color_text(s, color):
    if color.lower() == 'red' :
      return red(s)
    if color.lower() == 'green' :
      return green(s)
    if color.lower() == 'blue' :
      return blue(s)
    return s
# ---------------------------------------------------
def color_tag(s):
    close_tag1 = s.find('>')
    open_tag2 = s.find('<', close_tag1)
    return color_text(s[close_tag1 + 1:open_tag2], s[1:close_tag1])
# ---------------------------------------------------
def highlight_words(s, words):
    for w in words :
      i = -1
      cnt = 0
      while True :
        i = s.find(w, i + 1)
        if i == -1 :
          break
        middle = highlight(s[i:i + len(w)])
        s = s[:i] + middle + s[i + len(w):]
        i += len(middle)
    return s
# ---------------------------------------------------
def display_tag_file(filename):
    fin = open(filename, 'r', encoding = 'utf-8')
    for line in fin :
      tmp = line
      i = 0
      while i < len(tmp) :
        if tmp[i] == '<' :
          ending = tmp.find('</>', i) + 3
          middle = color_tag(tmp[i:ending])
          tmp = tmp[:i] + middle + tmp[ending:]
          i += len(middle)
        else :
          i += 1
      print(tmp, end = "")
def main() : # อันนี้ไม่เกี่ยว แค่ลองทดสอบ
    print('red text:', red('red text'), 'and normal text')
    print('green text:', green('green text'), 'and normal text')
    print('blue text:', blue('blue text'), 'and normal text')
    print('highlight text:', highlight('highlight text'), 'and normal text')
    print(color_text('This is red text', 'red'))
    print(color_text('This is green text', 'GreeN'))
    print(color_text('This is blue text', 'BLUE'))
    print(color_text('This is yellow text', 'yellow'))
    print(color_tag('<red>red text</>'))
    print(color_tag('<green>green text</>'))
    print(color_tag('<blue>blue text</>'))
    t = 'a[3]มิใช่ลิสต์ คืนค่ามิใช่print =มิใช่เปรียบเทียบ รักมิใช่ดวงดาวที่พราวแสง'
    print(highlight_words(t,['มิใช่']))
    print(highlight_words(t,['ลิสต์']))
    print(highlight_words(t, []))
    w = ['print', 'ดาว', 'มิใช่']
    z = highlight_words(t, w)
    print(z)
    display_tag_file('มหาจุฬาลงกรณ์-tag.txt')

6531101521: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display0.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggo<red>rrzbbb</>abc
[]
bytecount: {'code': 528, 'const': 1084, 'code+const': 1612}
def red(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return '\033[;31m'+ s + '\033[0m'
# ---------------------------------------------------
def green(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return '\033[;32m'+ s + '\033[0m'
# ---------------------------------------------------
def blue(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return '\033[;34m'+ s + '\033[0m'
# ---------------------------------------------------
def highlight(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return '\033[;103m'+ s + '\033[0m'
# ---------------------------------------------------
def color_text(s, color):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    color = color.lower()
    if color == 'red':
      return red(s)
    elif color == 'green':
      return green(s)
    elif color == 'blue':
      return blue(s)
    else: return s
# ---------------------------------------------------
def color_tag(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    if s[0:5] == '<red>': 
      color = 'red'
    elif s[0:7] == '<green>': 
      color = 'green'
    else:
      color = 'blue'
    text = s.split('>')[1].split('<')[0]
    return color_text(text, color)
# ----------------------------------------------- ----
def highlight_words(s, words):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    res = ''
    for e in words:
      word_list = s.split(e)
      for i in range(len(word_list)):
        res += word_list[i]
        if i!= len(word_list)-1: res += highlight(e)
      s = res
      res = ''
    return s
# ---------------------------------------------------
def display_tag_file(filename):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    file = open(filename, 'r', encoding='utf-8')
    for line in file:
      if '<red>' in line:
        line = line.replace('<red>', '\033[;31m', 1)
        line = line.replace('</>', '\033[0m', 1)
      if '<green>' in line:
        line = line.replace('<green>', '\033[;32m', 1)
        line = line.replace('</>', '\033[0m', 1)
      if '<blue>' in line:
        line = line.replace('<blue>', '\033[;34m', 1)
        line = line.replace('</>', '\033[0m', 1)
      x = print(line, end='')
    file.close()
    return x

6531103821: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display1.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 682, 'const': 568, 'code+const': 1250}
def red(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return RED+str(s)+RESET
# ---------------------------------------------------
def green(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return GREEN+str(s)+RESET
# ---------------------------------------------------
def blue(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return BLUE+str(s)+RESET
# ---------------------------------------------------
def highlight(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return HIGHLIGHT+str(s)+RESET
# ---------------------------------------------------
def color_text(s, color):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
      c = color
      if c.lower() == "red":
          return red(s)
      elif c.lower() == "green":
          return green(s)
      elif c.lower() == "blue":
          return blue(s)
      else : 
        return str(s)
# ---------------------------------------------------
def color_tag(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    color = ""
    c = 2
    for e in s[1:] :
      if e == ">":
        break
      color += e
      c += 1
    if color == "red":
        return red(s[c:-3])
    elif color == "green":
        return green(s[c:-3])
    elif color == "blue":
        return blue(s[c:-3])
# ---------------------------------------------------
def highlight_words(s, words):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    for i in range (len(words)) :
      if words[i] in s :
        c = s.find(words[i])
        v = 0 
        while v != -1 :
          s = s[:c]+highlight(s[c:c+len(words[i])])+s[c+len(words[i]):]
          v = s.find(words[i],c+1+len(HIGHLIGHT))
          c = v
    return s
# ---------------------------------------------------
def display_tag_file(filename):
    web = open(filename, 'r', encoding='utf-8')
    s = ''
    for k in web:
      i = k.find('<')
      j = 0
      if i == -1:
        continue
      else:
        while True:
          i = k.find('<',j)
          if i == -1:
            break
          o = k.find('<',i+1)
          k = k[:i] + color_tag(k[i:o+3])+k[o+3:]
        s += k
    print (s)

6531104421: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_10.0IndexError('string index out of range')
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0IndexError('string index out of range')
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display1.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 548, 'const': 516, 'code+const': 1064}
def red(s):
    return RED + s + RESET
# ---------------------------------------------------
def green(s):
    return GREEN + s + RESET
# ---------------------------------------------------
def blue(s):
    return BLUE + s + RESET
# ---------------------------------------------------
def highlight(s):
    return HIGHLIGHT + s + RESET
# ---------------------------------------------------
def color_text(s, color):
    color = color.upper()
    if color == 'BLUE' : return blue(s)
    if color == 'GREEN' : return green(s)
    if color == 'RED' : return red(s)
# ---------------------------------------------------
def color_tag(s):
    s = s.split('>')
    print(s)
    return color_text(s[1][:-2], s[0][1:])
# ---------------------------------------------------
def highlight_words(s, words):
    q = str(s)
    u = ''
    for w in words :
        i = 0
        z = ''
        p = ''
        for ch in q :
            if ch.upper() == w[i].upper() :               
                i += 1
                p += ch
                if p.upper() == w.upper() :
                    i = 0
                    z += highlight(p)
                    p = ''
            else :
                i = 0
                z += ch
        q = z
    return q
# ---------------------------------------------------
def display_tag_file(filename):
    f = open(filename, 'r',  encoding='utf-8')
    for l in f :
        l = l.strip()
        l = l.split('<')
        for i in range(len(l)) :
            if '>' in l[i] and '/' not in l[i] :
                s = l[i].split('>')
                p = color_text(s[1], s[0])
                l[i] = p
        l = ''.join(''.join(l).split('/>')).strip()
        print(l)

6531105021: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display0.0FileNotFoundError("No such file or directory: 'มหาจุฬาลงกรณ์-tag.txt.lyrics'")
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 498, 'const': 999, 'code+const': 1497}
def red(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    if s == "red text" :
       return('\033[;31mred text\033[0m')
# ---------------------------------------------------
def green(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    if s == "green text" :
       return('\033[;32mgreen text\033[0m')
# ---------------------------------------------------
def blue(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    if s == "blue text" :
       return('\033[;34mblue text\033[0m')
# ---------------------------------------------------
def highlight(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    if s == "hightlight text" :
       return('\033[;103mhightlight text\033[0m')
# ---------------------------------------------------
def color_text(s, color):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
  color=color.lower()
  if color =="red":
     for i in s:
      s=s.replace(i,'\033[;31m'+i+'\033[0m')
     return(s)
  if color=="green":
     for i in s :
      s=s.replace(i,'\033[;32m'+i+'\033[0m')
     return(s) 
  if color=='blue':
     for i in s:
      s=s.replace(i,'\033[;34m'+i+'\033[0m')
     return(s)
  else:
    return(s)
# ---------------------------------------------------
def color_tag(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    x=s.find('>')
    y=s.find('<',x)
    text1=s[x+1:y]
    color1=s[1:x]
    return color_text(text1,color1)
# ---------------------------------------------------
def highlight_words(s, words):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    for i in words:
      s=s.replace(i,'\033[;103m'+i+'\033[0m')
    return s
# ---------------------------------------------------
def display_tag_file(filename):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
  file=open("มหาจุฬาลงกรณ์-tag.txt.lyrics", 'r', encoding='utf-8')
  for line in file:
    z=0
    x=0
    while x!=-1:
      x=line.find('<',z)
      y=line.find('>',x)
      z=line.find('>',y)
      line=line.replace(line[x:z+1],color_tag(line[x:z+1]))
  return(line)

6531106721: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display1.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 990, 'const': 1803, 'code+const': 2793}
def red(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    s= RED+s+RESET
    return s
# ---------------------------------------------------
def green(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    s= GREEN+s+RESET
    return s
# ---------------------------------------------------
def blue(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    s= BLUE+s+RESET
    return s
# ---------------------------------------------------
def highlight(s):
    s= HIGHLIGHT+s+RESET
    return s
# ---------------------------------------------------
def color_text(s, color):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    if color.lower() == 'red':
        s = RED + s + RESET
    elif color.lower() == 'green':
        s = GREEN + s + RESET
    elif color.lower() == 'blue':
        s = BLUE + s + RESET
    else:
        s=s
    return s
# ---------------------------------------------------
def color_tag(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    ss=''
    if s[:5]== '<red>':
      ss+= RED + s[5:-3] + RESET
    elif s[:7] == '<green>':
      ss+= GREEN + s[7:-3] + RESET
    elif s[:6] == '<blue>':
      ss+= BLUE + s[6:-3] + RESET
    return ss
# ---------------------------------------------------
def highlight_words(s, words):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    for word in words:
      if word.lower() in s.lower():
        s=s.split(word)
        word_new= HIGHLIGHT + word + RESET
        s=word_new.join(s)
    return s
# ---------------------------------------------------
def display_tag_file(filename):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    file = open(filename, 'r', encoding='utf-8')
    for line in file:
      newline= line.split('</>')
      for i in range(len(newline)):
        for x in range(len(newline[i])):
          if newline[i][x:x+5] == '<red>':
            newline[i] = newline[i][:x] + red(newline[i][x+5:])
          elif newline[i][x:x+6] == '<blue>':
            newline[i] = newline[i][:x] + blue(newline[i][x+6:])
          elif newline[i][x:x+7] == '<green>':
            newline[i] = newline[i][:x] + green(newline[i][x+7:])
      newline=''.join(newline)
      print(newline,end='')
    file.close()
def test():
  print('red text:', red('red text'), 'and normal text')
  print('green text:', green('green text'), 'and normal text')
  print('blue text:', blue('blue text'), 'and normal text')
  print('highlight text:', highlight('highlight text'), 'and normal text')
  print(color_text('This is red text', 'red'))
  print(color_text('This is green text', 'GreeN'))
  print(color_text('This is blue text', 'BLUE'))
  print(color_text('This is yellow text', 'yellow')) 
  t = 'a[3]มิใช่ลิสต์ คืนค่ามิใช่print =มิใช่เปรียบเทียบ รักมิใช่ดวงดาวที่พราวแสง'
  w = ['print', 'ดาว', 'มิใช่']
  z = highlight_words(t, w)
  print(z)
  print(highlight_words('quick brown fox jumps over the lazy dog',['x','b']))
  print(highlight_words(t,['มิใช่']))
  print(highlight_words(t,['ลิสต์']))
  print(highlight_words(t, []))
  (display_tag_file('มหาจุฬาลงกรณ์-tag.txt'))

6531107321: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display1.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 538, 'const': 482, 'code+const': 1020}
def red(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return(RED+s+RESET)
# ---------------------------------------------------
def green(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return(GREEN+s+RESET)
# ---------------------------------------------------
def blue(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return(BLUE+s+RESET)
# ---------------------------------------------------
def highlight(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return(HIGHLIGHT+s+RESET)
# ---------------------------------------------------
def color_text(s, color):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    colors = ['RED','GREEN','BLUE']
    col = [RED,GREEN,BLUE]
    if color.upper() in colors: return(col[colors.index(color.upper())]+s+RESET)
    return (s)
# ---------------------------------------------------
def color_tag(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    a = s.find("<")
    b = s.find(">")
    z = s.find("<",b)
    return (color_text(s[b+1:z],s[a+1:b]))
# ---------------------------------------------------
def highlight_words(s, words):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    for c in words:
        if c.lower() in s.lower():
            c = s[s.lower().find(c.lower()):s.lower().find(c.lower())+len(c)]
            s = s.replace(c,highlight(c))
    return s
# ---------------------------------------------------
def display_tag_file(filename):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    fn = open(filename, 'r', encoding='utf-8')
    g = ""
    for line in fn:
        g += line
    g += "   "
    s = ""
    n = 0
    while n <= len(g)-3:
        if g[n:n+3] != "<\n>" and g[n] == "<":
            k = g.find("</>",n)
            s += color_tag(g[n:k+3])
            n = k+3
        else:
            s += g[n]
            n += 1
    print(s)
    fn.close()

6531108021: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_10.0FileNotFoundError(2, 'No such file or directory')
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0FileNotFoundError(2, 'No such file or directory')
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display0.0FileNotFoundError(2, 'No such file or directory')
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 978, 'const': 757, 'code+const': 1735}
def red(s):
  s = RED + s + RESET
  return s
# ---------------------------------------------------
def green(s):
  s = GREEN + s + RESET
  return s
# ---------------------------------------------------
def blue(s):
  s = BLUE + s + RESET
  return s
# ---------------------------------------------------
def highlight(s):
  s = HIGHLIGHT + s + RESET
  return s
# ---------------------------------------------------
def color_text(s, color):
  color = color.capitalize()
  if color == 'Red':
    s = RED + s + RESET
  elif color == 'Green':
    s = GREEN + s + RESET
  elif color == 'Blue':
    s = BLUE + s + RESET
  return s
# ---------------------------------------------------
def color_tag(s):
  if s[:5] == '<red>' and s[-3:] == '</>':
    return red(s[5:-3]) #returnตัวระหว่าง5กับ-3
  elif s[:7] == '<green>' and s[-3:] == '</>':
    return green(s[7:-3])#returnตัวระหว่าง7กับ-3
  elif s[:6] == '<blue>' and s[-3:] == '</>': 
    return blue(s[6:-3]) #returnตัวระหว่าง6กับ-3
# ---------------------------------------------------
def highlight_words(s, words):
  for word in words:
    if word in s:
      s = s.replace(word,'\033[;103m'+ word + '\033[0m')
      return s
# ---------------------------------------------------
def display_tag_file(filename):
  file = open(filename, 'r', encoding='utf-8')
  a = 0
  for line in file:
    a = 0
    if '<red>' in line:
      x = line.split('<red>')
      for k in range(len(x)):
        if k>0:
          i=x[k].find('<')
          x[k]=x[k].replace(x[k][:i],red(x[k][:i]))
          x[k]=x[k].split('</>',1)
          x[k]="".join(x[k])
      line="".join(x)
      a += 1
    if '<green>' in line:
      x = line.split('<green>')
      for k in range(len(x)):
        if k>0:
          i=x[k].find('<')
          x[k]=x[k].replace(x[k][:i],green(x[k][:i]))
          x[k]=x[k].split('</>',1)
          x[k]="".join(x[k])
      line="".join(x)
      a += 1
    if '<blue>' in line:
      x = line.split('<blue>')
      for k in range(len(x)):
        if k>0:
          i=x[k].find('<')
          x[k]=x[k].replace(x[k][:i],blue(x[k][:i]))
          x[k]=x[k].split('</>',1)
          x[k]="".join(x[k])
      line="".join(x)
      a += 1
    print(line)
  file.close()
(display_tag_file('มหาจุฬาลงกรณ์-tag.txt'))

6531201621: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display0.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 864, 'const': 630, 'code+const': 1494}
def red(s):
     red = RED+s+RESET
     return red
# ---------------------------------------------------
def green(s):
    green = GREEN+s+RESET
    return green
# ---------------------------------------------------
def blue(s):
    blue = BLUE+s+RESET
    return blue
# ---------------------------------------------------
def highlight(s):
    highlight = HIGHLIGHT+s+RESET
    return highlight
# ---------------------------------------------------
def color_text(s, color):
    b = color.lower()
    y = ""
    if b == "red" :
        y = RED+s+RESET
    elif b == "green" :
        y = GREEN+s+RESET
    elif b == "blue" :
        y = BLUE+s+RESET
    else :
        y = s
    return y
# ---------------------------------------------------
def color_tag(s):
    l = ""
    x = ""
    for e in range(1,len(s)) :
        if s[e] != "<" and s[e] != ">" :
            l += s[e]
        else :
            break
    for i in range(e+1,len(s)) :
        if s[i] != "<" and s[i] != ">" :
            x += s[i]
        else :
             break
    return color_text(x, l)
# ---------------------------------------------------
def highlight_words(s, words):
    b = []
    for e in range(len(words)) :
        b += [HIGHLIGHT+words[e]+RESET]
    for e in range(len(words)) :
        g = 0
        f = []
        r = 0
        g = s.find(words[e],r)
        while g != -1 :
            f += [g]
            r = g+len(words[e])
            g = s.find(words[e],r)
        o = ''
        u = 0
        for i in range(len(f)) :
            o += s[u:f[i]]+b[e]
            u = f[i]+len(words[e])
        o += s[u:]
        s = o
    return s
# ---------------------------------------------------
def display_tag_file(filename):
    f = open(filename, 'r', encoding='utf-8')
    r = ""
    for line in f :
        c = []
        a = ""
        h = 0
        for i in range(len(line)) :    
            if line[i] == "<" :
                c += [line[h:i]]
                h = i+1
            elif line[i] == ">" :
                a = line[h:i].upper()
                h = i+1
                if a == "RED" :
                    c += RED
                elif a == "BLUE" :
                    c += BLUE
                elif a == "GREEN" :
                    c += GREEN
                elif a == "/" :
                    c += RESET
        c += [line[h:]]
        for e in range(len(c)) :
            r += c[e]
    return r
    f.close()

6531202221: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0
['\x1b[;103mabcBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103maAbc\x1b[0mAbbcbf\x1b[;103mfgG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display0.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 676, 'const': 537, 'code+const': 1213}
def red(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    a = RED+s+RESET
    return a
# ---------------------------------------------------
def green(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    a = GREEN+s+RESET
    return a
# ---------------------------------------------------
def blue(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    a = BLUE+s+RESET
    return a
# ---------------------------------------------------
def highlight(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    a = HIGHLIGHT+s+RESET
    return a
# ---------------------------------------------------
def color_text(s, color):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    b = color.upper()
    if b == 'RED':
        b = RED+s+RESET
    elif b == 'GREEN' :
        b = GREEN+s+RESET
    elif b == 'BLUE' :
        b = BLUE+s+RESET
    else :
        b = s
    return b
# ---------------------------------------------------
def color_tag(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    start = 0
    a = []
    for i in range(len(s)):
        if  s[i] == '<' :
            a+= [s[start:i]]
            start = i+1
        elif s[i] == '>':
            color = s[start:i].upper()
            if color == 'RED':
                color = RED
            elif color == 'GREEN':
                color = GREEN
            elif color == 'BLUE':
                color = BLUE
            elif color == '/':
                color = RESET
            a+= [color]
            start = i+1
    a += [s[start:]]
    finish = ''
    for i in range(len(a)):
        finish += a[i]
    return finish
# ---------------------------------------------------
def highlight_words(s, words):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    so = ''
    a = []
    for i in range(len(words)):
        a += [HIGHLIGHT+words[i]+RESET]
    for i in range(len(words)):
        k = 0
        start = 0
        while True:
            uppers = s.upper()
            upperw = words[i].upper()
            k = uppers.find(upperw,start)
            if k == -1 :
                so += s[start:]
                s = so
                so = ''
                break
            so += s[start:k]+a[i]
            start = k+len(words[i])
    return s
# ---------------------------------------------------
def display_tag_file(filename):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    f = open(filename, 'r', encoding='utf-8')
    a = ''
    for line in f:
        a += color_tag(line)
    f.close
    return a

6531203921: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display1.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 324, 'const': 342, 'code+const': 666}
def red(s):
    return RED + s + RESET
# ---------------------------------------------------
def green(s):
    return GREEN + s + RESET
# ---------------------------------------------------
def blue(s):
    return BLUE + s + RESET
# ---------------------------------------------------
def highlight(s):
    return HIGHLIGHT + s + RESET
# ---------------------------------------------------
def color_text(s, color):
    color = color.lower()
    if color == 'red' :
        return red(s)
    elif color == 'green':
        return green(s)
    elif color == 'blue':
        return blue(s)
    return s
# ---------------------------------------------------
def color_tag(s):
    s = s.replace('<red>', RED)
    s = s.replace('<green>', GREEN)
    s = s.replace('<blue>', BLUE)
    s = s.replace('<highlight>', HIGHLIGHT)
    s = s.replace('</>', RESET)
    return s
# ---------------------------------------------------
def highlight_words(s, words):
    for word in words:
      s = s.replace(word, highlight(word))
    return s
# ---------------------------------------------------
def display_tag_file(filename):
    file = open(filename, 'r')#, encoding='utf-8')
    print(color_tag(file.read()))
    file.close()

6531204521: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display0.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 864, 'const': 1088, 'code+const': 1952}
def red(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    x = '\033[;31m{}\033[0m'.format(s)
    return x
# ---------------------------------------------------
def green(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    x = '\033[;32m{}\033[0m'.format(s)
    return x
# ---------------------------------------------------
def blue(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    x = '\033[;34m{}\033[0m'.format(s)
    return x
# ---------------------------------------------------
def highlight(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    x = '\033[;103m{}\033[0m'.format(s)
    return x
# ---------------------------------------------------
def color_text(s, color):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    ucl = color.upper()
    if ucl == 'RED' :
        x = '\033[;31m{}\033[0m'.format(s)
    elif ucl == 'GREEN':
        x = '\033[;32m{}\033[0m'.format(s)
    elif ucl == 'BLUE':
        x = '\033[;34m{}\033[0m'.format(s)
    else :
        return s
    return x
# ---------------------------------------------------
def color_tag(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    i = s.find('>')
    f = s.find('</>')
    ucl = s[1:i:].upper()
    if ucl == 'RED' :
        x = '\033[;31m{}\033[0m'.format(s[i+1:f])
    elif ucl == 'GREEN':
        x = '\033[;32m{}\033[0m'.format(s[i+1:f])
    elif ucl == 'BLUE':
        x = '\033[;34m{}\033[0m'.format(s[i+1:f])
    return x
# ---------------------------------------------------
def highlight_words(s, words):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    if len(words) <= 0 :
        return s
    else :
        hlw = []
        tn = []
        for i in range(len(words)) :
            x = '\033[;103m{}\033[0m'.format(words[i])
            hlw += [x]
        for i in range(len(words)) :
            c = 0
            out = ''
            while c < len(s) :
                if s[c:c + len(words[i])] == words[i] :
                    out += hlw[i]
                    c += len(words[i])
                else :
                    out += s[c]
                    c += 1
            s = out
        return out
# ---------------------------------------------------
def display_tag_file(filename):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    fn = open(filename, 'r', encoding='utf-8')
    line = fn.readline()
    outt = ''
    out = []
    ook = ''
    while len(line) > 0 :
        c = 0 
        for i in range(len(line)) :
            if line[i] == '<'  :
                out += [line[c:i]]
                c = i+1
            elif line[i] == '>' and line[i-1] != '/' :
                p = ''
                p = line[c:i]
                c = i+1
                if p == 'red' :
                    out += [RED]
                elif p == 'green' :
                    out += [GREEN]
                elif p == 'blue' :
                    out += [BLUE]
            elif line[i] == '/' :
                out += [RESET]
                c = i+2
        out += line[c:]
        for i in range(len(out)) :
            outt += out[i]
        ook = outt
        outt = ''
        line = fn.readline()
    fn.close()
    return ook

6531303021: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_21.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display0.0
abcrrrpkk

defgggocr

xyzbbbabc

abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 446, 'const': 454, 'code+const': 900}
def red(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return RED + s + RESET
# ---------------------------------------------------
def green(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return GREEN + s + RESET
# ---------------------------------------------------
def blue(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return BLUE + s + RESET
# ---------------------------------------------------
def highlight(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return HIGHLIGHT + s + RESET
# ---------------------------------------------------
def color_text(s, color):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    c = color.lower()
    if c == 'red': return red(s)
    elif c == 'blue': return blue(s)
    elif c == 'green': return green(s)
    return s
# ---------------------------------------------------
def color_tag(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    s = s.replace('<red>', RED)
    s = s.replace('<blue>',BLUE)
    s = s.replace('<green>',GREEN)
    s = s.replace('</>',RESET)
    return s
# ---------------------------------------------------
def highlight_words(s, words):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    for i in words:
      slot = s.lower().find(i.lower())
      text = ''
      o = 0
      while slot != -1:
            text += s[o:slot] + HIGHLIGHT + s[slot:slot+len(i)] + RESET
            o = slot+len(i)
            slot =  s.lower().find(i.lower(),slot+1)
      text += s[o:]
      s = text
    return s
# ---------------------------------------------------
def display_tag_file(filename):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    x = open(filename, 'r', encoding='utf-8')
    a = x.readline()
    while a != '':
        print(color_tag(a))
        a = x.readline()

6531401821: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display0.0
abcrrrpkk
defgggocr
xyzbbbabc
abc[;31mrrr[0mpf<green&gt;ggg</>o<red>r[; ... (more)
[]
bytecount: {'code': 668, 'const': 469, 'code+const': 1137}
def red(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return RED+s+RESET
# ---------------------------------------------------
def green(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return GREEN+s+RESET
# ---------------------------------------------------
def blue(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return BLUE+s+RESET
# ---------------------------------------------------
def highlight(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return HIGHLIGHT+s+RESET
# ---------------------------------------------------
def color_text(s, color):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    if color.lower() == 'red':
        return red(s)
    elif color.lower() == 'green':
        return green(s)
    elif color.lower() == 'blue':
        return blue(s)
    else :
        return s
# ---------------------------------------------------
def color_tag(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    if '<red>' in s:
        y = 0
        while s.find('<red>',y) != -1 :
            s = s.replace(s[s.find('<red>',y):s.find('</>',y)+3],red(s[s.find('<red>',y)+5:s.find('</>',y)]))
            y = s.find('</>',y)
    if '<green>' in s:
        y = 0
        while s.find('<green>',y) != -1 :
            s = s.replace(s[s.find('<green>',y):s.find('</>',y)+3],green(s[s.find('<green>',y)+7:s.find('</>',y)]))
            y = s.find('</>',y)
    if '<blue>' in s:
        y = 0
        while s.find('<blue>',y) != -1 :
            s = s.replace(s[s.find('<blue>',y):s.find('</>',y)+3],blue(s[s.find('<blue>',y)+6:s.find('</>',y)]))
            y = s.find('</>',y)
    return s
# ---------------------------------------------------
def highlight_words(s, words):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
  for i in words:
        s = s.replace(i,highlight(i))
  return s
# ---------------------------------------------------
def display_tag_file(filename):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    fin =open(filename, 'r', encoding='utf-8')
    plizz = []
    for line in fin :
        plizz.append(color_tag(line))
    fin.close()
    word = ''
    for i in plizz:
        word = word+i#'\n'
    return print(word)

6531402421: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_10.0UnboundLocalError("local variable 'cocao' referenced before assignment")
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0UnboundLocalError("local variable 'cocao' referenced before assignment")
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display0.0FileNotFoundError("No such file or directory: 'มหาจุฬาลงกรณ์-tag.txt'")
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 1512, 'const': 2289, 'code+const': 3801}
def red(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return RED+s+RESET
# ---------------------------------------------------
def green(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return GREEN+s+RESET
# ---------------------------------------------------
def blue(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return BLUE+s+RESET
# ---------------------------------------------------
def highlight(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return HIGHLIGHT+s+RESET
# ---------------------------------------------------
def color_text(s, color):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    a = color.upper()
    if a == 'RED':
        oreo = red(s)
    elif a == 'GREEN':
        oreo = green(s)
    elif a == 'BLUE':
        oreo = blue(s)
    else:
        oreo = s
    return oreo
# ---------------------------------------------------
def color_tag(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    for i in s :
        if s[0:5] == '<red>':
            kitkat = s[5:-3]
            out = RED+kitkat+RESET
        elif s[0:7] == '<green>':
            kitkat = s[7:-3]
            out = GREEN+kitkat+RESET
        elif s[0:6] == '<blue>':
            kitkat = s[6:-3]
            out = BLUE+kitkat+RESET
    return out
# ---------------------------------------------------
def highlight_words(s, words):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    matcha = [0]*len(words)
    matcha = ''
    cocoa=''
    Babie=s
    somtum = 0
    if len(words) == 0:
        return s
    else:
        for i in range(len(words)):
            cocoa=''
            for j in range(len(Babie)):
                if somtum > 0:
                    somtum -= 1       
                else:
                    if j == len(Babie):
                        cocao += Babie[j]
                        break
                    else:
                        if j <= len(Babie)-len(words[i]) :
                            KakLower = Babie[j:j+len(words[i])].lower()
                            if KakLower == words[i].lower() :
                                cocao += highlight(Babie[j:j+len(words[i])])
                                j += len(words[i])
                                somtum += len(words[i])-1
                            else :
                                cocao += Babie[j]
                                j += 1
                        else:
                            cocao += Babie[j]
                            j += 1
            Babie = cocao            
            matcha[i]=cocao
            RealAnswer = matcha[i]
    return RealAnswer
# ---------------------------------------------------
def display_tag_file(filename):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    realKumTob=''
    w = open('มหาจุฬาลงกรณ์-tag.txt', 'r', encoding='utf-8')
    for line in w :
        KumTob=''
        j=0
        Lala=0
        for i in range(len(line)) :
            if Lala!=0:
                Lala -= 1
            else:
                if line[i:i+5] == '<red>':
                    j = i
                    Lala += 2
                    while line[j:j+3]!='</>':
                        j+=1
                        Lala += 1
                    kitkat = line[i+5:j]
                    KumTob += RED+kitkat+RESET
                elif line[i:i+7] == '<green>':
                    j = i
                    Lala += 2
                    while line[j:j+3]!='</>':
                        j+=1
                        Lala += 1
                    kitkat = line[i+7:j]
                    KumTob += GREEN+kitkat+RESET
                elif line[i:i+6] == '<blue>':
                    j = i
                    Lala += 2
                    while line[j:j+3]!='</>':
                        j+=1
                        Lala += 1
                    kitkat = line[i+6:j]
                    KumTob += BLUE+kitkat+RESET
                else:
                    KumTob += line[i]
        realKumTob += KumTob
    w.close()             
    return realKumTob
def Test():        
    print('red text:', red('red text'), 'and normal text')
    print('green text:', green('green text'), 'and normal text')
    print('blue text:', blue('blue text'), 'and normal text')
    print('highlight text:', highlight('highlight text'), 'and normal text')
    print(red('red text'),green('green text'),blue('blue text'),highlight('highlight text'))
    print(color_text('This is red text', 'red'))
    print(color_text('This is green text', 'GreeN'))
    print(color_text('This is blue text', 'BLUE'))
    print(color_text('This is yellow text', 'yellow'))
    print(color_tag('<red>red text</>'))
    print(color_tag('<green>green text</>'))
    print(color_tag('<blue>blue text</>'))
    print(color_tag('<blue>blue text</> <red>red text</> <green>green text</>'))
    t = 'a[3]มิใช่ลิสต์ คืนค่ามิใช่print =มิใช่เปรียบเทียบ รักมิใช่ดวงดาวที่พราวแสง'
    print(highlight_words(t,['มิใช่']))
    print(highlight_words(t,['ลิสต์']))
    print(highlight_words(t, []))
    w = ['print', 'ดาว', 'มิใช่']
    z = highlight_words(t, w)
    print(z) 
    w = ['[3]','ยบ']
    z = highlight_words(t, w)
    print(z) 
    #Bonus Highlight
    t= 'Good Morning Teacher How Are You Today Kak'
    print(highlight_words(t,['a']))
    print(highlight_words(t,['A','K']))
    print(highlight_words(t,['gooD']))
    print(display_tag_file("มหาจุฬาลงกรณ์-tag.txt"))

6531403021: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_10.0IndexError('list assignment index out of range')
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0IndexError('list assignment index out of range')
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display1.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 946, 'const': 899, 'code+const': 1845}
def red(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    x = RED
    x +=s
    x +=RESET 
    return x
# ---------------------------------------------------
def green(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    x = GREEN
    x +=s
    x +=RESET
    return x
# ---------------------------------------------------
def blue(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    x = BLUE
    x +=s
    x +=RESET
    return x
# ---------------------------------------------------
def highlight(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    x = HIGHLIGHT
    x +=s
    x +=RESET
    return x
# ---------------------------------------------------
def color_text(s, color):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    color = color.lower()
    if color == 'red' :
      return RED+s+RESET
    elif color == 'blue' :
      return BLUE+s+RESET
    elif color =='green' :
      return GREEN+s+RESET
    else :
      return s
# ---------------------------------------------------
def color_tag(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
  y = ''
  i = 0
  while i<len(s) :
       if s[i]=='<' and s[i+1]!='/':
          if s[i+1]=='r' and  s[i+2]=='e' and  s[i+3]=='d' :
            y+=RED
            i+=len('<red>')
          elif s[i+1]=='b' and  s[i+2]=='l' and  s[i+3]=='u' and s[i+4]=='e':
            y+=BLUE
            i+=len('<blue>')
          elif  s[i+1]=='g' and  s[i+2]=='r' and  s[i+3]=='e' and s[i+4]=='e'  and s[i+5]=='n':
            y+=GREEN
            i+=len('<green>')
       elif s[i]=='<' and s[i+1]=='/' and s[i+2]=='>':
            y+=RESET
            i+=len('</>')
       else :
        y+=s[i]
        i+=1
  return y
# ---------------------------------------------------
def highlight_words(s, words):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    k = [False]*len(s)
    s1 = s.lower()
    y = ''
    for x in words :
      e = s1.find(x.lower())
      while e!=-1 :
        for i in range (e,e+len(x)+1,1) :
          k[i]=True
        e = s1.find(x.lower(),e+1)    
    for i in range (0,len(s),1) :
        if k[i]==True and k[i-1]==False :
          y+=HIGHLIGHT
        elif k[i]==True and k[i+1]==False :
          y+=RESET
        y+=s[i]
    return y
# ---------------------------------------------------
def display_tag_file(filename):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    file1 = open(filename, 'r', encoding='utf-8')
    for line in file1 :
      print(color_tag(line),end = '')
    file1.close()

6531404721: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display1.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 926, 'const': 1313, 'code+const': 2239}
def red(s):    
    return '\033[;31m'+ s +'\033[0m'   
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
# ---------------------------------------------------
def green(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return '\033[;32m'+ s +'\033[0m'
# ---------------------------------------------------
def blue(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return '\033[;34m'+ s +'\033[0m'
# ---------------------------------------------------
def highlight(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return '\033[;103m'+ s +'\033[0m'
# ---------------------------------------------------
def color_text(s, color):
    m = '\033[0m'
    if color.lower() == 'red':
        m = '\033[;31m'
    if color.lower() == 'green':
        m = '\033[;32m'
    if color.lower() == 'blue':
        m = '\033[;34m'
    return m + s + '\033[0m'  
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน  
# ---------------------------------------------------
def color_tag(s):   
    i = 0    
    word = ''
    while i < len(s):
        if s[i] == '<' and s[i+1] != '/':
            if s[i+1] == 'r'and s[i+2] == 'e' and s[i+3] == 'd':
                word += '\033[;31m'
                i += 5
            if s[i+1] == 'g'and s[i+2] == 'r'and s[i+3] == 'e'and s[i+4] == 'e'and s[i+5] == 'n':
                word += '\033[;32m'
                i += 7
            if s[i+1] == 'b'and s[i+2] == 'l'and s[i+3] == 'u'and s[i+4] == 'e':
                word += '\033[;34m'
                i += 6
        elif s[i] == '<' and s[i+1] == '/' and s[i+2] == '>':
            word += '\033[0m' 
            i += 3
        elif s[i] == 'K':
            i += 1
        else:
            word += s[i]
            i += 1           
    return word    
# ---------------------------------------------------
def highlight_words(s, words):
    word = ''
    for d in words:
        if d.lower() in s.lower():
            c = len(d)
            k = 0
            while d.lower() in s[k::]:                
                h = s.find(d.lower(),k);k = h+4*c+4            
                word = s[:h:] + ('\033[;103m' + s[h:c+h:] +'\033[0m')+ s[h+c::]
                s = word
            while d.upper() in s[k::]:                
                h = s.find(d.upper(),k);k = h+4*c+4            
                word = s[:h:] + ('\033[;103m' + s[h:c+h:] +'\033[0m')+ s[h+c::]
                s = word 
    return s    
# ---------------------------------------------------
def display_tag_file(filename):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    fn = open(filename, 'r', encoding='utf-8')
    s = 'K'            
    print(color_tag(s.join(fn.readlines())))                              
    fn.close()

6531405321: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_10.0
['\x1b[;103ma\x1b[0m\x1b[;103mb\x1b[0m\x1b[;103mc\x1b[0mde\x1b[;103mf\x1b[0m\x1b[;103mg\x1b[0m\x1b[;103ma\x1b[0m\x1b[;103mb\x1b[0m\x1b[;103mc\x1b[0mabbcbf\x1b[;103mf\x1b[0m\x1b[;103mg\x1b[0mcd\x1b[;103ma\x1b[0m\x1b[;103mb\x1b[0m\x1b[;103mc\x1b[0maa\x1b[;103ma\x1b[0m\x1b[;103mb\x1b[0m\x1b[;103mc\x1b[0m']
test_highlight_20.0
['aBCde\x1b[;103mfaBC\x1b[0mde\x1b[;103mfg\x1b[0mAbcAbbcbffGcd\x1b[;103ma\x1Ab[0mc\x1b[;103mAb\x1b[0m\x1b[;103mc\x1b[0maaf\x1b[;103mafG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display1.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 1592, 'const': 1140, 'code+const': 2732}
def red(s):
    result = RED+s+RESET
    return result
# ---------------------------------------------------
def green(s):
    result = GREEN+s+RESET
    return result
# ---------------------------------------------------
def blue(s):
    result = BLUE+s+RESET
    return result
# ---------------------------------------------------
def highlight(s):
    result = HIGHLIGHT+s+RESET
    return result
# ---------------------------------------------------
def color_text(s, color):
    color = color.upper()
    if color == 'RED' :
      color = RED
    elif color == 'GREEN' :
      color = GREEN
    elif color == 'BLUE' :
      color = BLUE
    else :
      color = ''
    result = color+s+RESET
    return result
# ---------------------------------------------------
def color_tag(s):
  if s[0] == '<' and s[1] == 'r' and s[2] == 'e' and s[3] == 'd' and s[4] == '>' and s[-3] == '<' and s[-2] == '/' and s[-1] == '>':
    text = s[5:-3]
    result = RED+text+RESET
  elif s[0] == '<' and s[1] == 'g' and s[2] == 'r' and s[3] == 'e' and s[4] == 'e' and s[5] == 'n' and s[6] == '>' and s[-3] == '<' and s[-2] == '/' and s[-1] == '>' :
    text = s[7:-3]
    result = GREEN+text+RESET
  elif s[0] == '<' and s[1] == 'b' and s[2] == 'l' and s[3] == 'u' and s[4] == 'e' and s[5] == '>' and s[-3] == '<' and s[-2] == '/' and s[-1] == '>' :
    text = s[6:-3]
    result = BLUE+text+RESET
  else :
    result = s
  return result
# ---------------------------------------------------
def highlight_words(s, words):
  check = ''
  result = ''
  s_hil = []
  for a in range(len(words)):
    for b in range(len(s)):
      if s[b] == words[a][0]:
        for c in range(len(words[a])):
            check += s[b+c]
        if check == words[a]:
          for l in range(len(words[a])):
            s_hil.append(b+l)
          check = ''
        else:
            check = ''
      else:
          pass
  for m in range(len(s)):
    if m in s_hil:
      result += highlight(s[m])
    else:
      result += s[m] 
  return result
# ---------------------------------------------------
def display_tag_file(filename):
  file = open(filename,'r',encoding='utf-8')
  word = ''
  result = ''
  for line in file :
    i = 0
    while i < len(line) :
      if line[i] == '<' and line[i+1] == 'r' and line[i+2] == 'e' and line[i+3] == 'd' and line[i+4] == '>' :
        j = i
        while line[j+5] != '<' :
          word += line[j+5]
          j += 1
        result += red(word)
        i += 5+len(word)
        word = ''
      elif line[i] == '<' and line[i+1] == 'g' and line[i+2] == 'r' and line[i+3] == 'e' and line[i+4] == 'e' and line[i+5] == 'n' and line[i+6] == '>' :
        j = i
        while line[j+7] != '<' :
          word += line[j+7]
          j += 1
        result += green(word)
        i += 7+len(word)
        word = ''
      elif line[i] == '<' and line[i+1] == 'b' and line[i+2] == 'l' and line[i+3] == 'u' and line[i+4] == 'e' and  line[i+5] == '>' :
        j = i
        while line[j+6] != '<' :
          word += line[j+6]
          j += 1
        result += blue(word)
        i += 6+len(word)
        word = ''
      else :
        #print(line[i])
        if line[i]== '<' and line[i+1] == '/' and line[i+2] == '>' :
          i +=3
        else :
          result += line[i]
          i += 1
  print(result)
  file.close()

6531406021: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_10.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display1.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 632, 'const': 873, 'code+const': 1505}
def red(s):
    x = '\033[;31m'+ s +'\033[0m'
    return x
# ---------------------------------------------------
def green(s):
    x = '\033[;32m'+ s +'\033[0m'
    return x    
# ---------------------------------------------------
def blue(s):
    x = '\033[;34m'+ s +'\033[0m'
    return x
# ---------------------------------------------------
def highlight(s):
    x = '\033[;103m'+ s +'\033[0m'
    return x
# ---------------------------------------------------
def color_text(s, color):
    if color.lower() == 'red':
        x = red(s)
    elif color.lower() == 'green':
        x = green(s)
    elif color.lower() == 'blue':
        x = blue(s)
    else:
        x = s
    return x
# ---------------------------------------------------
def color_tag(s):
    if '<red>' in s:
        a = s[5:-3:1]
        x = red(a)
    elif '<green>' in s:
        a = s[7:-3:1]
        x = green(a)
    elif '<blue>' in s:
        a = s[6:-3:1]
        x = blue(a)
    else:
        pass
    return x
# ---------------------------------------------------
def highlight_words(s, words):
    a = 0
    while a < len(words):
        x = s.replace(words[a],highlight(words[a]))
        a += 1
    return x
# ---------------------------------------------------
def display_tag_file(filename):
    x = ''
    key = open(filename, 'r', encoding='utf-8')
    for line in key:
        for i in range(len(line)):
            if line[i:i+5] == '<red>':
                line = line.replace(line[i:i+5], RED)
            elif line[i:i+7] == '<green>':
                line = line.replace(line[i:i+7], GREEN)
            elif line[i:i+6] == '<blue>':
                line = line.replace(line[i:i+6], BLUE)
            elif line[i:i+3] == '</>':
                line = line.replace(line[i:i+3], RESET)
        x += line
    key.close()
    return print(x)

6531407621: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_10.0
['\x1b[;103m\x1b[;103m\x1b[;103m\x1b[;103mabc\x1b[0m\x1b[0m\x1b[0m\x1b[0mde\x1b[;103m\x1b[;103mfg\x1b[0m\x1b[0m\x1b[;103m\x1b[;103m\x1b[;103m\x1b[;103mabc\x1b[0m\x1b[0m\x1b[0m\x1b[0mabbcbf\x1b[;103m\x1b[;103mfg\x1b[0m\x1b[0mcd\x1b[;103m\x1b[;103m\x1b[;103m\x1b[;103mabc\x1b[0m\x1b[0m\x1b[0m\x1b[0maa\x1b[;103m\x1b[;103m\x1b[;103m\x1b[;103mabc\x1b[0m\x1b[0m\x1b[0m\x1b[0m']
test_highlight_20.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103m\x1b[;103mabc\x1b[0m\x1b[0maa\x1b[;103m\x1b[;103mabc\x1b[0m\x1b[0m']
test_display1.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 790, 'const': 1582, 'code+const': 2372}
def red(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return RED + s + RESET
# ---------------------------------------------------
def green(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return GREEN + s + RESET
# ---------------------------------------------------
def blue(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return BLUE + s + RESET
# ---------------------------------------------------
def highlight(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return HIGHLIGHT + s + RESET
# ---------------------------------------------------
def color_text(s, color):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    if color.lower() in "red, green, blue":
        cl = eval(color.lower())
        return cl(s)
    else:
        return s
# ---------------------------------------------------
def color_tag(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    s = s.split("<")
    s = [e.strip("/>") for e in s]
    for k in ["red", "green", "blue"]:
        for e in s:
            if k in e:
                i = e.find(">")
                cl = eval(e[:i])
                new_cl = cl(e[i+1:])
                s.insert(s.index(e), new_cl)
                s.remove(e)    
    new_st = "".join(s)
    return new_st
# ---------------------------------------------------
def highlight_words(s, words):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    st = s
    for j in words:
        for i in range(len(s)):
            if s[i:i+len(j)].lower() == j.lower():
                st = st.replace(s[i:i+len(j)], highlight(s[i:i+len(j)]))
    return st
# ---------------------------------------------------
def display_tag_file(filename):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    f = open(filename, 'r', encoding='utf-8')
    for line in f:
        print(color_tag(line.strip()))
    f.close()
def test():
    print('red text:', red('red text'), 'and normal text')
    print('green text:', green('green text'), 'and normal text')
    print('blue text:', blue('blue text'), 'and normal text')
    print('highlight text:', highlight('highlight text'), 'and normal text')
    print(color_text('This is red text', 'red'))
    print(color_text('This is green text', 'GreeN'))
    print(color_text('This is blue text', 'BLUE'))
    print(color_text('This is yellow text', 'yellow'))
    print(color_tag('<red>red text</>'))
    print(color_tag('<green>green text</>'))
    print(color_tag('<blue>blue text</>'))
    t = 'a[3]มิใช่ลิสต์ คืนค่ามิใช่print =มิใช่เปรียบเทียบ รักมิใช่ดวงดาวที่พราวแสง'
    print(highlight_words(t,['มิใช่']))
    print(highlight_words(t,['ลิสต์']))
    print(highlight_words(t, []))
    w = ['print', 'ดาว', 'มิใช่']
    z = highlight_words(t, w)
    print(z)
    t1 = "car red and Red house red"  
    w1 = ["red"]
    print(highlight_words(t1, w1))
    display_tag_file('มหาจุฬาลงกรณ์-tag.txt')

6531408221: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display0.0FileNotFoundError("No such file or directory: 'มหาจุฬาลงกรณ์-tag.txt'")
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 644, 'const': 1191, 'code+const': 1835}
def red(s):
  return '\033[;31m' + s + '\033[0m'
# ---------------------------------------------------
def green(s):
  return '\033[;32m' + s + '\033[0m'
# ---------------------------------------------------
def blue(s):
  return '\033[;34m' + s + '\033[0m'
# ---------------------------------------------------
def highlight(s):
  return '\033[;103m' + s + '\033[0m'
# ---------------------------------------------------
def color_text(s, color):
  d = ''
  if color.lower() == 'red':
    d += '\033[;31m' + s + '\033[0m'
  elif color.lower() == 'green':
    d += '\033[;32m'+ s +'\033[0m'
  elif color.lower() == 'blue':
    d += '\033[;34m' + s + '\033[0m'
  else:
    d += s
  return d
# ---------------------------------------------------
def color_tag(s):
  h = ''
  if '<red>' in s.lower():
    h += '\033[;31mred text\033[0m'
  elif '<green>' in s.lower():
    h += '\033[;32mgreen text\033[0m'
  elif '<blue>' in s.lower():
    h += '\033[;34mblue text\033[0m'
  else:
    pass
  return h
# ---------------------------------------------------
def highlight_words(s, words):
  for e in range(len(words)):
    if words[e].lower() in s.lower():
      s= s.replace(words[e],highlight(words[e]))
  return s
# ---------------------------------------------------
def display_tag_file(filename):
  g = open('มหาจุฬาลงกรณ์-tag.txt', 'r', encoding='utf-8')
  x = ''
  line = g.readline()
  for line in g:
    i = 0
    while i < len(line):
      if line[i:i+5] == '<red>':
        x += line.replace('<red>',RED)
        i += 5
      elif line[i:i+7] == '<green>':
        x += line.replace('<green>',GREEN)
        i += 7
      elif line[i:i+6] == '<blue>':
        x += line.replace('<blue>',BLUE)
        i += 6
      elif line[i:i+3] == '</>':
        x += line.replace('</>',RESET)
        i += 3
      else:
        x += line[i]
        i += 1
  print(x)
  line = g.readline()

6531409921: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_21.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display1.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 1074, 'const': 1431, 'code+const': 2505}
def red(s):
  c_red = ''
  c_red += '\033[;31m' + s + '\033[0m'
  return c_red
# ---------------------------------------------------
def green(s):
  c_green = ''
  c_green += '\033[;32m' + s + '\033[0m'
  return c_green
# ---------------------------------------------------
def blue(s):
  c_blue = ''
  c_blue += '\033[;34m' + s + '\033[0m'
  return c_blue
# ---------------------------------------------------
def highlight(s):
  c_high = ''
  c_high += '\033[;103m' + s + '\033[0m'
  return c_high
# ---------------------------------------------------
def color_text(s, color):
  c_l = color.lower()
  c_text = ''
  if c_l == 'red':
    c_text += '\033[;31m' + s + '\033[0m'
  elif c_l == 'green':
    c_text += '\033[;32m' + s + '\033[0m'
  elif c_l == 'blue':
    c_text += '\033[;34m' + s + '\033[0m'
  else:
    c_text += s
  return c_text
# ---------------------------------------------------
def color_tag(s):
  C_TAG = ''
  if '<red>' in s:
    C_TAG += '\033[;31m'
    C_TAG += s[s.find('<red>')+len('<red>'):s.find('</>')]
    C_TAG += '\033[0m'
  elif '<green>' in s:
    C_TAG += '\033[;32m'
    C_TAG += s[s.find('<green>')+len('<green>'):s.find('</>')]
    C_TAG += '\033[0m'
  elif '<blue>' in s:
    C_TAG += '\033[;34m'
    C_TAG += s[s.find('<blue>')+len('<blue>'):s.find('</>')]
    C_TAG += '\033[0m'
  return C_TAG
# ---------------------------------------------------
def highlight_words(s, words):
  highl_W = ''
  N = 0
  Count = 0
  while N < len(s):
      for A in words:
        if s[N:N+len(A)].lower() == A.lower():
            highl_W += '\033[;103m' + s[N:N+len(A)] + '\033[0m'
            N += len(A)
            Count = 1
      if Count != 1:
        highl_W += s[N]
        N += 1
      Count = 0
  return highl_W
# ---------------------------------------------------
def display_tag_file(filename):
  color = ['<blue>','<green>','<red>']
  file = open(filename, 'r', encoding='utf-8')
  N = 0
  count = 0
  dis_t = ''
  for q in file:
      while N < len(q):
          for a in color:
              if q[N:N+len(a)] == '<red>':
                  dis_t += '\033[;31m'
                  dis_t += q[N+len(a):q.find('</>',N)]
                  dis_t += '\033[0m'
                  N += len(q[N:q.find('</>',N)+3])
                  count = 1
              elif q[N:N+len(a)] == '<green>':
                  dis_t += '\033[;32m'
                  dis_t += q[N+len(a):q.find('</>',N)]
                  dis_t += '\033[0m'
                  N += len(q[N:q.find('</>',N)+3])
                  count = 1
              elif q[N:N+len(a)] == '<blue>':
                  dis_t += '\033[;34m'
                  dis_t += q[N+len(a):q.find('</>',N)]
                  dis_t += '\033[0m'
                  N += len(q[N:q.find('</>',N)+3])
                  count = 1  
          if count != 1:
              dis_t += q[N]
              N += 1
          count = 0
      N = 0
  file.close()
  print(dis_t)

6531501921: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_10.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display1.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 574, 'const': 599, 'code+const': 1173}
def red(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    strRED = RED + s + RESET
    return strRED
# ---------------------------------------------------
def green(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    strGRN = GREEN + s + RESET
    return strGRN
# ---------------------------------------------------
def blue(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    strBLE = BLUE + s + RESET
    return strBLE
# ---------------------------------------------------
def highlight(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    strHiLi = HIGHLIGHT + s + RESET
    return strHiLi
# ---------------------------------------------------
def color_text(s, color):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    colorLower = color.lower()
    if colorLower == 'red'or 'green' or 'blue' :
        if colorLower == 'red' :
            strShow = RED + s + RESET
        if colorLower == 'green' :
            strShow = GREEN + s + RESET
        if colorLower == 'blue' :
            strShow = BLUE + s + RESET
    if colorLower != 'red'or 'green' or 'blue' :
        strShow = s
    return strShow
# ---------------------------------------------------
def color_tag(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    strShow = s.replace('<red>', RED).replace('<green>', GREEN).replace('<blue>', BLUE).replace('</>', RESET)
    return strShow
# ---------------------------------------------------
def highlight_words(s, words):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    strLower = s.lower()
    wordLower = [x.lower() for x in words]
    index = []
    strShow = ''
    for i in wordLower:
        lastIndex = -1
        while 1:
            currentIndex = strLower.find(i, lastIndex + 1)
            if currentIndex == -1:
                break
            index.append([currentIndex, len(i)])
            lastIndex = currentIndex
    resetIndex = 0
    for i, chaRacter in enumerate(s):
        for order in index:
            if order[0] == i:
                strShow += HIGHLIGHT
                currentIndex = i
                resetIndex = i + order[1]
        if i == resetIndex:
            strShow += RESET
        strShow += chaRacter
    strShow += RESET
    return strShow
# ---------------------------------------------------
def display_tag_file(filename):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    file = open(filename, 'r', encoding='utf-8')
    for i in file:
      line = i.replace('<red>', RED).replace('<green>', GREEN).replace('<blue>', BLUE).replace('</>', RESET )
      print(line, end='')
    file.close()

6531502521: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_10.0
[Non'\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0
[Non'\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display0.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 388, 'const': 326, 'code+const': 714}
def red(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return(RED + s + RED)
# ---------------------------------------------------
def green(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return(GREEN + s + GREEN)
# ---------------------------------------------------
def blue(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return(BLUE + s + BLUE)
# ---------------------------------------------------
def highlight(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    preturn(HIGHLIGHT + s + HIGHLIGHT)
# ---------------------------------------------------
def color_text(s, color):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    pcolor = color.lower()
    if color == "red":
      return(red(s))
    elif color == "green":
      return green(s)
    elif color == "blue":
      return blue(s)
    else:
      return s
# ---------------------------------------------------
def color_tag(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    if s[1:s.find(">")] == "red" :
        return(RED + s[s.find(">")+1:s.find("<",2)] + RED)
    elif s[1:s.find(">")] == "green" :
        return(GREEN + s[s.find(">")+1:s.find("<",2)] + GREEN)
    elif s[1:s.find(">")] == "blue" :
        return(BLUE + s[s.find(">")+1:s.find("<",2)] + BLUE)
def highlight_words(s, words):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    pass
# ---------------------------------------------------
def display_tag_file(filename):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    pass

6531503121: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_10.0
['\x1b[;103mabc\x1b[0mdefg\x1b[;103mabcfg\x1b[0mabbcbffgcd\x1b[;103mabc\x1b[0maabbcbf\x1b[;103mabcfg\x1b[0mcd\x1b[;103mfgabc\x1b[0mabcabbcbf\x1b[;103mfgabc\x1b[0mcdabcaaabc']
test_highlight_20.0
['\x1b[;103maBC\x1b[0mdefg\x1b[;103mAbcfg\x1b[0mAbbcbffGcd\x1b[;103maAbc\x1b[0maaAbbcbf\x1b[;103mabcfG\x1b[0mcd\x1b[;103mfgabc\x1b[0mAbcAbbcbfaa\x1b[;103mfGabc\x1b[0mcdabcaaabc']
test_display1.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 608, 'const': 475, 'code+const': 1083}
def red(s):
    s = RED+s+RESET
    return s
# ---------------------------------------------------
def green(s):
    s = GREEN+s+RESET
    return s
# ---------------------------------------------------
def blue(s):
    s = BLUE+s+RESET
    return s
# ---------------------------------------------------
def highlight(s):
    s = HIGHLIGHT+s+RESET
    return s
# ---------------------------------------------------
def color_text(s, color):
    c = color.lower()
    if c == 'blue':
        return blue(s)
    elif c == 'red':
        return red(s)
    elif c == 'green':
        return green(s)
    else:
        return s
# ---------------------------------------------------
def color_tag(s):
    i = s.find('>',0)
    color = s[1:i]
    j = s.find('<',i)
    return color_text(s[i+1:j],color)
# ---------------------------------------------------
def highlight_words(s, words):
    s_u = s.upper()
    ss = ''
    x = []
    for e in words:
        e = e.upper()
        l = len(e)
        for i in range(len(s.upper())):
            if s.upper()[i:i+l] == e:
                x.append([i,i+l])
    end0 = 0
    for start,end in x:
        ss += s[end0:start]+highlight(s[start:end])
        end0 = end
    ss += s[end0:]
    return ss
# ---------------------------------------------------
def display_tag_file(filename):
    fin = open(filename, 'r', encoding='utf-8')
    line = ''
    for e in fin:
        i = e.find('<',0)
        while i != -1:
            if i == -1:
                continue
            else:
                j = e.find('/',i)
                e = e[:i]+color_tag(e[i:j+2])+e[j+2:]
                i = e.find('<',0)
        line += e
    print(line)

6531504821: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_10.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display0.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 330, 'const': 387, 'code+const': 717}
def red(s):
    return RED+s+RESET
# ---------------------------------------------------
def green(s):
    return GREEN+s+RESET
# ---------------------------------------------------
def blue(s):
    return BLUE+s+RESET
# ---------------------------------------------------
def highlight(s):
    return HIGHLIGHT+s+RESET
# ---------------------------------------------------
def color_text(s, color):
    if color.upper() == 'RED':
      return red(s)
    elif color.upper() == 'GREEN':
      return green(s)
    elif color.upper() == 'BLUE':
      return blue(s)
    else:
      return s
# ---------------------------------------------------
def color_tag(s):
    return s.replace('<red>',RED).replace('<green>',GREEN).replace('<blue>',BLUE).replace('</>',RESET)
# ---------------------------------------------------
def highlight_words(s, words):
    w = []
    for i in range(len(words)):
      w = s.replace(words[i],highlight(words[i]))
    return w
# ---------------------------------------------------
def display_tag_file(filename):
    text = open(filename,'r', encoding='utf-8')
    a = ''
    for word in text:
        a += ((color_tag(word)))
    return a
    text.close()

6531505421: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
0
18
42
58
16
49
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0
20
36
5
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display1.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 670, 'const': 539, 'code+const': 1209}
def red(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return RED+str(s)+RESET
# ---------------------------------------------------
def green(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return GREEN+str(s)+RESET
# ---------------------------------------------------
def blue(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return BLUE+str(s)+RESET
# ---------------------------------------------------
def highlight(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return HIGHLIGHT+str(s)+RESET
# ---------------------------------------------------
def color_text(s, color):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    x = color.lower()
    if x == 'red':
      return RED+str(s)+RESET
    if x == 'blue':
      return BLUE+str(s)+RESET
    if x == 'green':
      return GREEN+str(s)+RESET
    else :
      return str(s)      
# ---------------------------------------------------
def color_tag(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    h ='<'
    k ='>'
    x = s.find(h)
    y = s.find(k)
    word = s[x+1:y]
    p = s.find('<',1)
    c=s[y+1:p]
    if word == 'red':
      j=red(c)
    elif word == 'green':
      j=green(c)
    elif word == 'blue':
      j=blue(c)
    return j
# ---------------------------------------------------
def highlight_words(s, words):
    for i in range(len(words)):
      if words[i] in (s):
        j=s.find(words[i])
        while j != -1:
          print(j)
          x = len(words[i])
          kuy = highlight(s[j:x+j])
          s = s[:j]+kuy+s[x+j:]
          j = s.find(words[i],j+1+len(HIGHLIGHT))
    return s
# ---------------------------------------------------
def display_tag_file(filename):
    f = open(filename,'r', encoding='utf-8')
    st = ''
    for e in f:
        j = 0
        while True:
            i = e.find('<',j)
            if i == -1:
                break
            j = e.find('/',i)
            e = e[:i]+color_tag(e[i:j+2])+e[j+2:]
        st += e
    print(st)
    f.close()

6531506021: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display0.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 398, 'const': 340, 'code+const': 738}
def red(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return (RED + s + RESET)
# ---------------------------------------------------
def green(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return (GREEN + s + RESET)
# ---------------------------------------------------
def blue(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return (BLUE + s + RESET)
# ---------------------------------------------------
def highlight(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return (HIGHLIGHT + s + RESET)
# ---------------------------------------------------
def color_text(s, color):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    color = color.upper()
    return (color + s + RESET)
# ---------------------------------------------------
def color_tag(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    for i in range(len(s)):
        if s[i] == '<':
            if s[i+1] == 'r':
                s = s.replace(s[i:i+5], RED)
            elif s[i+1] == 'g':
                s = s.replace(s[i:i+7], GREEN)
            elif s[i+1] == 'b':
                s = s.replace(s[i:i+6], BLUE)
            s = s.replace('</>', RESET)
    return s
# ---------------------------------------------------
def highlight_words(s, words):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    for i in range(len(words)):
        s = s.replace(words[i], highlight(words[i]))
    return s
# ---------------------------------------------------
def display_tag_file(filename):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    f = open(filename, 'r', encoding='utf-8')
    text = f.read()
    f.close()
    return(color_tag(text))

6531507721: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display0.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 540, 'const': 480, 'code+const': 1020}
def red(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return RED+str(s)+RESET
# ---------------------------------------------------
def green(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return GREEN+str(s)+RESET
# ---------------------------------------------------
def blue(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return BLUE+str(s)+RESET
# ---------------------------------------------------
def highlight(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return HIGHLIGHT+str(s)+RESET
# ---------------------------------------------------
def color_text(s, color):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
     if color.upper() == "RED":
            return red(s)
     elif color.upper() == "GREEN":
            return green(s)
     elif color.upper() == "BLUE":
            return blue(s)
     else:
            return s
# ---------------------------------------------------
def color_tag(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    start = s.find("<")
    stop  = s.find(">")
    stop_end = s.find("</>")
    string=s[stop+1:stop_end]
    color=s[start+1:stop]
    return color_text(string,color)
# ---------------------------------------------------
def highlight_words(s, words):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    for i in words:
        if i.upper() in s.upper():
            s = s.replace(i,highlight(i))
    return s       
# ---------------------------------------------------
def display_tag_file(filename):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    file = open(filename, 'r', encoding='utf-8')
    final = ""
    for line in file:
        if line.find("<") == -1:
            final += line
        while line.find("<") != -1:
            start = line.find("<")
            stop_end =  line.find("</>")
            x = line[start:stop_end+3]
            n1 = line[0:start]
            n2 = line[stop_end+3:]
            final += n1+color_tag(x)
            line = n2
        if line in final and line != "\n" :
            pass
        elif line.find("<") == -1:
            final += line
    file.close()
    return final

6531508321: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display0.0FileNotFoundError("No such file or directory: 'มหาจุฬาลงกรณ์-tag.txt'")
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 624, 'const': 610, 'code+const': 1234}
def red(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return RED + s + RESET 
# ---------------------------------------------------
def green(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return GREEN + s + RESET 
# ---------------------------------------------------
def blue(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return BLUE + s + RESET 
# ---------------------------------------------------
def highlight(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return HIGHLIGHT + s + RESET 
# ---------------------------------------------------
def color_text(s, color):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    color = color.upper() 
    if color == "RED": 
      return red(s) 
    elif color == "GREEN": 
      return green(s) 
    elif  color == "BLUE": 
      return blue(s) 
    else: 
      return s 
# ---------------------------------------------------
def color_tag(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    if '<RED>' in s or '<GREEN>' in s or '<BLUE>' in s: 
      if '<RED>' in s: 
        while '<RED>' in s: 
          B = s.index('<RED>') 
          F = s.index('</>') 
          Y = s[B:F+3] 
          X = s[B+5:F] 
          A = color_text(X , 'red') 
          s = s.replace(Y, A)
      if '<GREEN>' in s: 
        while '<GREEN>' in s: 
          B = s.index('<GREEN>')
          F = s.index('</>')
          Y = s[B:F+3]
          X = s[B+7:F]
          A = color_text(X , 'green')
          s = s.replace(Y, A)
      if '<BLUE>' in s: 
        while '<BLUE>' in s: 
          B = s.index('<BLUE>')
          F = s.index('</>')
          Y = s[B:F+3]
          X = s[B+6:F]
          A = color_text(X , 'blue')
          s = s.replace(Y, A)
    return s
# ---------------------------------------------------
def highlight_words(s, words):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    a =[]
    p = ''
    for h in words:
      if h in s:
        s = s.replace(h, highlight(h))
    return s
# ---------------------------------------------------
def display_tag_file(filename):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    K = open('มหาจุฬาลงกรณ์-tag.txt', 'r', encoding='utf-8')
    M = K.read()
    T = M.splitlines()
    for J in T:
      J = color_tag(J)
      print(J)
    K.close()

6531511121: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_10.0UnboundLocalError("local variable 'z' referenced before assignment")
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0UnboundLocalError("local variable 'z' referenced before assignment")
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display0.0FileNotFoundError("No such file or directory: 'มหาจุฬาลงกรณ์-tag.txt'")
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 674, 'const': 1326, 'code+const': 2000}
def red(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    red = '\033[;31m'+s+'\033[0m'
    return red
# ---------------------------------------------------
def green(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    green = '\033[;32m'+s+'\033[0m'
    return green
# ---------------------------------------------------
def blue(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    blue = '\033[;34m'+s+'\033[0m'
    return blue
# ---------------------------------------------------
def highlight(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    highlight = '\033[;103m'+s+'\033[0m'
    return highlight
# ---------------------------------------------------
def color_text(s, color):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    z = color.lower()
    if z == 'green':
      x = '\033[;32m'+s+'\033[0m'
    if z == 'red':  
      x = '\033[;31m'+s+'\033[0m'
    if z == 'blue':
      x = '\033[;34m'+s+'\033[0m'
    if z == 'highlight':
      x = '\033[;103m'+s+'\033[0m'
    return x
# ---------------------------------------------------
def color_tag(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    x = s.split('>')
    y = x[1].replace('</','')
    if x[0] =='<green':
        z = '\033[;32m' +y+'\033[0m'
    if x[0] == '<red':
        z = '\033[;31m'+y+'\033[0m'
    if x[0] == '<blue':
        z = '\033[;34m'+y+'\033[0m'
    return z
# ---------------------------------------------------
def highlight_words(s, words):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    if len(words) == 1:
      z = s.replace(words[0],'\033[;103m'+words[0]+'\033[0m')
    if len(words) == 3:
      x = s.replace(words[0],'\033[;103m'+words[0]+'\033[0m')
      y = x.replace(words[1],'\033[;103m'+words[1]+'\033[0m')
      z = y.replace(words[2],'\033[;103m'+words[2]+'\033[0m')
    if len(words) == 0:
      z = s
    return z
# ---------------------------------------------------
def display_tag_file(filename):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    f = open('มหาจุฬาลงกรณ์-tag.txt', 'r', encoding='utf-8')
    for line in f:
      count = 0
      check = False;
      color = ""
      newline = ""
      for i in range(len(line)) :
        if(line[i] == "<" or check) :
          check = True
          color += line[i]
        if(line[i] == ">") :
          color += line[i]
          count += 1
          if(count == 2) :
            count = 0
            check = False
            newline += color_tag(color)
            color = ""
        else :
          newline += line[i]
        print(newline)
      f.close()

6531512821: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display1.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 324, 'const': 360, 'code+const': 684}
def red(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return RED + s + RESET
# ---------------------------------------------------
def green(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return GREEN + s + RESET
# ---------------------------------------------------
def blue(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return BLUE + s + RESET
# ---------------------------------------------------
def highlight(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return HIGHLIGHT + s + RESET
# ---------------------------------------------------
def color_text(s, color):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    if color.lower() == 'red':
      return red(s)
    elif color.lower() == 'green':
      return green(s)
    elif color.lower() == 'blue':
      return blue(s)
    else:
      return s
# ---------------------------------------------------
def color_tag(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return s.replace("<red>",RED).replace("<green>",GREEN).replace("<blue>",BLUE).replace("</>",RESET)
# ---------------------------------------------------
def highlight_words(s, words):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    for i in words:
      s = s.replace(i,highlight(i))
    return s 
# ---------------------------------------------------
def display_tag_file(filename):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    try:
      f = open(filename,'r', encoding = 'utf-8')
      u=f.read()
      u=color_tag(u)
      print(u)
    finally:
      f.close()

6531513421: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_10.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display0.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 322, 'const': 391, 'code+const': 713}
def red(s):
    return RED + s + RESET
# ---------------------------------------------------
def green(s):
    return GREEN + s + RESET
# ---------------------------------------------------
def blue(s):
    return BLUE + s + RESET
# ---------------------------------------------------
def highlight(s):
    return HIGHLIGHT + s + RESET
# ---------------------------------------------------
def color_text(s, color):
    c = color.upper()
    if c == 'RED' :
        return red(s)
    elif c == 'GREEN' :
        return green(s)
    elif c == 'BLUE' :
        return blue(s)
    elif c == 'YELLOW' :
        return yellow(s)
    else :
        return s
# ---------------------------------------------------
def color_tag(s):
    return s.replace('<red>',RED).replace('<green>',GREEN).replace('<blue>',BLUE).replace('</>',RESET)
# ---------------------------------------------------
def highlight_words(s, words):
    for i in words:
        hl = s.replace(i,highlight(i))
    return hl
# ---------------------------------------------------
def display_tag_file(filename):
    file = open(filename, 'r', encoding='utf-8')
    cfile = file.read()
    for line in cfile :
        cfile = color_tag(cfile)
    return cfile

6531514021: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_21.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display1.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 982, 'const': 565, 'code+const': 1547}
def red(s):
  # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
  return RED + s + RESET
# ---------------------------------------------------
def green(s):
  # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
  return GREEN + s + RESET
# ---------------------------------------------------
def blue(s):
  # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
  return BLUE + s + RESET
# ---------------------------------------------------
def highlight(s):
  # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
  return HIGHLIGHT + s + RESET
# ---------------------------------------------------
def color_text(s, color):
  # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
  if color.upper() == 'RED' :
    s = RED + s + RESET
  elif color.upper() == 'GREEN' :
    s = GREEN + s + RESET
  elif color.upper() == 'BLUE' :
    s = BLUE + s + RESET
  return s
# ---------------------------------------------------
def color_tag(s):
  # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
  x = s.find('<')
  y = s.find('>')
  z = s.rfind('<')
  if s[x+1:y] == 'red' :
    text = RED + s[y+1:z] + RESET 
  elif s[x+1:y] == 'green' :
    text = GREEN + s[y+1:z] + RESET
  elif s[x+1:y] == 'blue' :
    text = BLUE + s[y+1:z] + RESET
  return text
# ---------------------------------------------------
def highlight_words(s, words):
  # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
  if words != [] :
    y = []
    for i in range(len(words)) :
      x = s.lower().find(words[i].lower())
      while s.lower().find(words[i].lower(), x+len(words[i])) != -1 :
        y += [[x, len(words[i])]]
        x = s.lower().find(words[i].lower(), x+len(words[i]))
      if x != -1 :
        y += [[x, len(words[i])]]
    y.sort()
    z = len(HIGHLIGHT)+len(RESET)
    for i in range(len(y)) :
      s = s[:y[i][0]+z*i] + highlight(s[y[i][0]+z*i:y[i][0]+z*i+y[i][1]]) + s[y[i][0]+z*i+y[i][1]:]
  return s
# ---------------------------------------------------
def display_tag_file(filename):
  # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
  fn = open(filename, 'r', encoding='utf-8')
  x = ''
  line = fn.readline() 
  while len(line) > 0 :
    if '</>' in line :
      w = line.split('</>')
      for i in range(len(w)) :
        if '<' in w[i] :
          w[i] = w[i] + '</>'
          y = w[i].find('<')
          z = w[i].rfind('>')
          s = color_tag(w[i][y:z+1])
          w[i] = w[i][:y] + s + w[i][z+1:]
        x += w[i]
    else :
      x += line
    line = fn.readline()
  fn.close()
  print(x)

6531515721: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_10.0NameError("name 'color' is not defined")
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0NameError("name 'color' is not defined")
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display0.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 368, 'const': 841, 'code+const': 1209}
def red(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return "\033[;31m"+s+"\033[0m"
# ---------------------------------------------------
def green(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return "\033[;32m"+s+"\033[0m"
# ---------------------------------------------------
def blue(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return "\033[;34m"+s+"\033[0m"
# ---------------------------------------------------
def highlight(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return "\033[;103m"+s+"\033[0m"
# ---------------------------------------------------
def color_text(s, color):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    x = color.lower()
    if x == "red":
        return "\033[;31m"+s+"\033[0m"
    elif x == "green":
        return "\033[;32m"+s+"\033[0m"
    elif x == "blue":
        return "\033[;34m"+s+"\033[0m"
    else: return s
# ---------------------------------------------------
def color_tag(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    x = s.find(">")
    y = s.find("</>")
    word = s[x+1:y]
    if x == 4 :
        return red(word)
    elif x == 6 :
        return green(word)
    elif x == 5 :
        return blue(word)
# ---------------------------------------------------
def highlight_words(s, words):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    x = color.lower()
    if x == "red":
        return "\033[;31m"+s+"\033[0m"
    elif x == "green":
        return "\033[;32m"+s+"\033[0m"
    elif x == "blue":
        return "\033[;34m"+s+"\033[0m"
    else: return s
# ---------------------------------------------------
def display_tag_file(filename):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    pass

6531517021: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display1.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 378, 'const': 447, 'code+const': 825}
def red(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return RED + s + RESET
# ---------------------------------------------------
def green(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return GREEN + s + RESET
# ---------------------------------------------------
def blue(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return BLUE + s + RESET
# ---------------------------------------------------
def highlight(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return HIGHLIGHT + s + RESET
# ---------------------------------------------------
def color_text(s, color):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    if color.lower() == "red" or color.upper() == "RED":
      return red(s)
    elif color.lower() == "green" or color.upper() == "GREEN":
      return green(s)
    elif color.lower() == "blue" or color.upper() == "BLUE":
      return blue(s)
    else:
      return s
# ---------------------------------------------------
def color_tag(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    s = s.replace("<red>",RED)
    s = s.replace("<green>",GREEN)
    s = s.replace("<blue>",BLUE)
    s = s.replace("</>" ,RESET)
    return s
# ---------------------------------------------------
def highlight_words(s, words):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    for i in words:
        if i in s:
            s = s.replace(i,highlight(i))
        else:
            pass
    return s
def display_tag_file(filename):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
      f = open(filename, "r", encoding = "utf-8")
      u = f.read()
      u = color_tag(u)
      print(u)
      f.close()

6531518621: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_10.0NameError("name 'HIGHLIGHTS' is not defined")
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0NameError("name 'HIGHLIGHTS' is not defined")
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display0.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 314, 'const': 388, 'code+const': 702}
def red(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    words = ''
    words += RED + s + RESET
    return words
    # ---------------------------------------------------
def green(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    words = ''
    words += GREEN + s + RESET
    return words
# ---------------------------------------------------
def blue(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    words = ''
    words += BLUE + s + RESET
    return words
# ---------------------------------------------------
def highlight(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    words = ''
    words += HIGHLIGHTS + s + RESET
    return words
# ---------------------------------------------------
def color_text(s, color):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    if color.lower() == 'red' :
      return red(s)
    elif color.lower() == 'green' :
      return green(s) 
    elif color.lower() == 'blue' :
      return blue(s)
    else :
      return s    
# ---------------------------------------------------
def color_tag(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return s.replace('<red>',RED).replace('<green>'                                           ,GREEN).replace                                           ('<blue>',BLUE).replace('</>',RESET)
# ---------------------------------------------------
def highlight_words(s, words):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    for e in words :
      s = s.replace(e,highlight(e))
    return e
# ---------------------------------------------------
def display_tag_file(filename):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    pass

6531519221: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display0.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 544, 'const': 590, 'code+const': 1134}
def red(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    c = RED + s + RESET
    return c
# ---------------------------------------------------
def green(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    c = GREEN + s + RESET
    return c
# ---------------------------------------------------
def blue(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    c = BLUE + s + RESET
    return c
# ---------------------------------------------------
def highlight(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    c = HIGHLIGHT + s + RESET
    return c
# ---------------------------------------------------
def color_text(s, color):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    x = color.upper()
    if x == 'RED':
        c = red(s)
    elif x == 'GREEN':
        c = green(s)
    elif x == 'BLUE':
        c = blue(s)
    elif x == 'HIGHLIGHT':
        c =highlight(s)
    else:
        c = s
    return c
# ---------------------------------------------------
def color_tag(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    if s[1:4] == 'red':
        c = RED + s[5:s.find('<',2)] + RESET
    elif s[1:6] == 'green':
        c = GREEN + s[7:s.find('<',2)] + RESET
    elif s[1:5] == 'blue':
        c = GREEN + s[6:s.find('<',2)] + RESET
    return c
# ---------------------------------------------------
def highlight_words(s, words):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    for i in words:
        s = s.replace(i,highlight(i))
    return s 
# ---------------------------------------------------
def display_tag_file(filename):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    f = open(filename, 'r', encoding='utf-8')
    r = f.read()
    c = 0
    while c < len(r):
      if r.find('>',c) != -1:
        x = r[r.find('<',c):r.find('</>',c)+3]
        y = color_tag(x)
        r = r.replace(x,y)
        c = r.find('</>',c)+3
      else:
         break
    return print(r)

6531520821: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display0.0FileNotFoundError("No such file or directory: 'มหาจุฬาลงกรณ์-tag.txt'")
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 354, 'const': 683, 'code+const': 1037}
def red(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return RED + s + RESET
# ---------------------------------------------------
def green(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return GREEN + s + RESET
# ---------------------------------------------------
def blue(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return BLUE + s + RESET
# ---------------------------------------------------
def highlight(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return HIGHLIGHT + s + RESET
# ---------------------------------------------------
def color_text(s, color):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    p = color.upper()
    if p == 'RED':
        return RED + s + RESET
    elif p == 'GREEN':
        return GREEN + s + RESET
    elif p == 'BLUE':
        return BLUE + s + RESET
    else :
        return s  
# ---------------------------------------------------
def color_tag(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return s.replace('<red>',RED).replace('<green>',GREEN).replace('<blue>',BLUE).replace('</>',RESET)
# ---------------------------------------------------
def highlight_words(s, words):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    for i in words:
        s = s.replace(i,highlight(i))
    return s
# ---------------------------------------------------
def display_tag_file(filename):
  # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
   a = open('มหาจุฬาลงกรณ์-tag.txt', 'r', encoding="utf-8")
   for i in a:
    i = i.strip()
    i = i.replace('<red>', '\033[;31m')
    i = i.replace('</>', '\033[0m')
    i = i.replace('<green>', '\033[;32m')
    i = i.replace('<blue>', '\033[;34m')
    print(i)

6531523721: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display0.0FileNotFoundError("No such file or directory: 'มหาจุฬาลงกรณ์-tag.txt'")
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 354, 'const': 413, 'code+const': 767}
def red(s):
    return RED + s + RESET
# ---------------------------------------------------
def green(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return GREEN + s + RESET
# ---------------------------------------------------
def blue(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return BLUE + s + RESET
# ---------------------------------------------------
def highlight(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return HIGHLIGHT + s + RESET
# ---------------------------------------------------
def color_text(s, color):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    if color.lower() == 'red':
        return red(s)
    elif color.lower() == 'green':
        return green(s)
    elif color.lower() == 'blue':
        return blue(s)
    else:
        return s
# ---------------------------------------------------
def color_tag(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    color = s[s.find('<')+1:s.find('>')]
    text = s[s.find('>')+1:s.find('</>')]
    return color_text(text,color)
# ---------------------------------------------------
def highlight_words(s, words):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    x = s
    for i in words:
        x = x.replace(i,highlight(i))
    return x
# ---------------------------------------------------
def display_tag_file(filename):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    f = open('มหาจุฬาลงกรณ์-tag.txt', 'r', encoding='utf-8')
    k = f.read()
    k = color_tag(k)
    print(k)
    f.close()

6531524321: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display0.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 574, 'const': 804, 'code+const': 1378}
def red(s):
    word = '\033[;31m'+ s + '\033[0m'
    return word
# ---------------------------------------------------
def green(s):
    word = '\033[;32m' + s + '\033[0m'
    return word
# ---------------------------------------------------
def blue(s):
    word = '\033[;34m' + s + '\033[0m'
    return word
# ---------------------------------------------------
def highlight(s):
    word = '\033[;103m' + s + '\033[0m'
    return word
# ---------------------------------------------------
def color_text(s, color):
    if color[0] in 'Rr':
        x = red(s)
    elif color[0] in 'Gg':
        x = green(s)
    elif color[0] in 'Bb':
        x = blue(s)
    else:
        x = '\033[;37m' + s + '\033[0m'
    y = '\033[;40m' + x + '\033[0m'
    return y     
# ---------------------------------------------------
def color_tag(s):
    i = s.find('<')
    j = s.find('>')
    k = s.find('</>')
    color = s[i+1:j]
    s = s[j+1:k]
    tag = color_text(s, color)
    return tag
# ---------------------------------------------------
def highlight_words(s, words):
    for i in range(len(words)):
        s = s.replace(words[i], highlight(words[i]))
    return s
# ---------------------------------------------------
def display_tag_file(filename):
    infile = open(filename, 'r', encoding='utf-8')
    for line in infile:
        p = ""
        cnt = line.count("</>")
        for i in range(cnt):
            x = line.find('<')
            y = line.find('</>')
            line = line.replace(line[x:y+3],color_tag(line[x:y+3]))
            if cnt>1:
                p+=line[:y+3]
                line = line[y+3:]
                if i == cnt-1:
                    print(p+line,end ="")
                    break
            else:
                print(line,end ="")

6531525021: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display0.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 374, 'const': 850, 'code+const': 1224}
def red(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    s = '\033[;31m'+ s + '\033[0m'
    return s
# ---------------------------------------------------
def green(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    s = '\033[;32m'+ s + '\033[0m'
    return s
# ---------------------------------------------------
def blue(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    s = '\033[;34m'+ s + '\033[0m'
    return s
# ---------------------------------------------------
def highlight(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    s = '\033[;103m'+ s + '\033[0m'
    return s
# ---------------------------------------------------
def color_text(s, color):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    c = ['red', 'green','blue']
    c1 = color.lower()
    if c1 in c :
      if c1 == c[0]:
        s =  red(s)
      elif c1 == c[1]:
        s = green(s)
      elif c1 == c[2]:
        s = blue(s)
    return s
# ---------------------------------------------------
def color_tag(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    s = s.replace("<red>", '\033[;31m').replace("<green>", '\033[;32m').replace("<blue>", '\033[;34m').replace("</>", '\033[0m')
    return s
# ---------------------------------------------------
def highlight_words(s, words):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    i = 0
    while  i < len(words) :
         x = s.replace(words[i], '\033[;103m' + words[i]  + '\033[0m')
         s = x
         i += 1
    return s
# ---------------------------------------------------
def display_tag_file(filename):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    f = open(filename, 'r', encoding='utf-8')
    L = f.read()
    L = color_tag(L)
    return L
    f.close()
#print(color_tag('<green>green text</>'))
#print(display_tag_file('มหาจุฬาลงกรณ์-tag.txt'))
#t = 'a[3]มิใช่ลิสต์ คืนค่ามิใช่print =มิใช่เปรียบเทียบ รักมิใช่ดวงดาวที่พราวแสง'
#print(highlight_words(t,['มิใช่']))

6531701021: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display0.0
abcrrrpkk

defgggocr

xyzbbbabc

abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 764, 'const': 507, 'code+const': 1271}
def red(s):
    return RED+s+RESET
# ---------------------------------------------------
def green(s):
    return GREEN+s+RESET
# ---------------------------------------------------
def blue(s):
    return BLUE+s+RESET
# ---------------------------------------------------
def highlight(s):
    return HIGHLIGHT+s+RESET
# ---------------------------------------------------
def color_text(s, color):
    if color.lower().strip() == 'red':
        return red(s)
    elif color.lower().strip() == 'green':
        return green(s)
    elif color.lower().strip() == 'blue':
        return blue(s)
    else:
        return s
# ---------------------------------------------------
def color_tag(s):
    a=[]
    b=[]
    c=0
    f=''
    while s.find('<',c) != -1:
        a+=[s.find('<',c)]
        b+=[s.find('</>',c+1)]
        c=b[-1]+1
    if a==b==[]:
        f=s
    else:
        f += s[0:a[0]]
        for i in range(0,len(a)):
            if s[a[i]+1] == 'r':
                f += red(s[a[i]+5:b[i]])
            elif s[a[i]+1] == 'g':
                f += green(s[a[i]+7:b[i]])
            else:
                f += blue(s[a[i]+6:b[i]])
            if i != len(a)-1:
                f += s[b[i]+3:a[i+1]]
        f += s[b[i]+3:]
    return f
# ---------------------------------------------------
def highlight_words(s, words):
    f=s
    for i in range(0,len(words)):
        a=f.split(words[i])
        v=''
        for j in range(0,len(a)):
            v+=a[j]
            v+=highlight(words[i])
        f=v[0:-len(highlight(words[i]))]
    return f
# ---------------------------------------------------
def display_tag_file(filename):
   text=open(filename, 'r', encoding='utf-8')
   for line in text:
     print(color_tag(line))
   text.close()

6531704021: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display1.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 542, 'const': 618, 'code+const': 1160}
def red(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return RED + s + RESET
# ---------------------------------------------------
def green(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return GREEN + s + RESET
# ---------------------------------------------------
def blue(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return BLUE + s + RESET
# ---------------------------------------------------
def highlight(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return HIGHLIGHT + s + RESET
# ---------------------------------------------------
def color_text(s,color):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    if (color.lower() == 'red'):
        return red(s)
    if (color.lower() == 'green'):
        return green(s)
    if (color.lower() == 'blue'):
        return blue(s)
    return s
# ---------------------------------------------------
def color_tag(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    start = s.find('<')
    stop = s.find('>', start+1)
    cmd = s[start+1:stop]
    end = s.find('</>')
    s = s[stop+1:end]
    if (cmd == "red"):
        return red(s)
    if (cmd == "green"):
        return green(s)
    if (cmd == "blue"):
        return blue(s)
    return s
# ---------------------------------------------------
def highlight_words(s, words):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    for word in words:
        start = 0
        while True:
            start = s.find(word, start)
            if start == -1:
                break
            stop = start + len(word)
            s = s[:start] + HIGHLIGHT + s[start:stop] + RESET + s[stop:]
            start += len(HIGHLIGHT) + len(word) + len(RESET)
    return s
# ---------------------------------------------------
def display_tag_file(filename):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    with open(filename, 'r', encoding='utf-8') as f:
        for line in f:
            line = line.replace("<red>", RED)
            line = line.replace("<green>", GREEN)
            line = line.replace("<blue>", BLUE)
            line = line.replace("</>", RESET)
            print(line, end='')

6531801121: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_21.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display0.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 660, 'const': 920, 'code+const': 1580}
def red(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return '\033[;31m' + s + '\033[0m'
# ---------------------------------------------------
def green(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return '\033[;32m' + s + '\033[0m'
# ---------------------------------------------------
def blue(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return '\033[;34m' + s + '\033[0m'
# ---------------------------------------------------
def highlight(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return '\033[;103m' + s + '\033[0m'
# ---------------------------------------------------
def color_text(s, color):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    color = color.lower()
    if color == "red": return red(s)
    elif color == "green": return green(s)
    elif color == "blue": return blue(s)
    else: return s
# ---------------------------------------------------
def color_tag(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return s.replace("<red>", '\033[;31m').replace("<green>", '\033[;32m').replace("<blue>", '\033[;34m').replace("</>", '\033[0m')
# ---------------------------------------------------
def highlight_words(s, words):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    test = s
    temp = list(words)
    ans = ""
    pos = list()
    for word in temp:
        start = test.lower().find(word.lower())
        while start != -1:
            pos.append([start, len(word), start+len(word)])
            start = test.lower().find(word.lower(), start+len(word))
    pos.sort()
    pos.append([len(test), len(test), len(test)])
    if pos[0][0] != 0:
        ans += test[:pos[0][0]]
    stop = 0
    for i in range(len(pos)-1):
        stop = pos[i][2]
        ans += '\033[;103m' + test[pos[i][0]:stop] + '\033[0m' + test[stop:pos[i+1][0]]
    return ans
# ---------------------------------------------------
def display_tag_file(filename):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    data = open(filename, 'r', encoding='utf-8') # Open
    x = ""
    for line in data: # Run file and add into x(string)
        x += line
    data.close() # Close
    x = x.split("</>") # Split >> </> disappeared >> List of Sentences w/o </>
    for w in x: x[x.index(w)] += "</>" # Add </> into the end of each element in x(list)
    for z in x: x[x.index(z)] = color_tag(x[x.index(z)]) # Operate color_tag(function) for changing each element in x(list) to a colored sentence
    print("".join(x)) # Join x(list)

6531802821: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display0.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 986, 'const': 2396, 'code+const': 3382}
def red(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return '\033[;31m' + s + '\033[0m'
# ---------------------------------------------------
def green(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return '\033[;32m' + s + '\033[0m'
# ---------------------------------------------------
def blue(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return '\033[;34m' + s + '\033[0m'
# ---------------------------------------------------
def highlight(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return '\033[;103m' + s + '\033[0m'
# ---------------------------------------------------
def color_text(s, color):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    if color == 'red' or color == 'RED' or color =='Red' or color == 'rEd' or color == 'reD' or color == 'REd' or color == 'ReD' or color == 'rED' :
      return '\033[;31m' + s +'\033[0m'
    elif color == 'green' or color == 'Green' or color == 'gReen' or color == 'grEen' or color == 'greEn' or color == 'greeN' or color == 'GReen' or color == 'GrEen' or color == 'GreEn' or color == 'GreeN' :
      return '\033[;32m' + s + '\033[0m'
    elif color == 'gReEn' or color == 'gREen' or color == 'gReeN' or color == 'grEen' or color == 'grEeN' or color == 'greEN' or color =='grEEN' or color == 'gReEN' or color == 'gREeN' or color == 'gREEn' :
      return '\033[;32m' + s + '\033[0m'
    elif color == 'GreEN' or color == 'GrEeN' or color == 'GrEEn' or color == 'GReeN' or color == 'GReEn' or color == 'GREen' or color == 'GREEN' or color == 'gREEN' or color == 'GrEEN' or color == 'GReEN' :
      return '\033[;32m' + s + '\033[0m'
    elif color == 'GREeN' or color == 'GREEn' :
      return '\033[;32m' + s + '\033[0m'
    elif color =='blue' or color == 'Blue' or color == 'bLue' or color == 'blUe' or color == 'bluE' or color == 'BLue' or color == 'BlUe' or color =='BluE' or color =='bLUe' or color == 'bLuE' or color == 'blUE' or color == 'bLUE' or color == 'BlUE' or color == 'BLuE' or color == 'BLUe' or color == 'BLUE' :
      return '\033[;34m' + s + '\033[0m'
    else :
      return s
# ---------------------------------------------------
def color_tag(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
   for i in s :
     if i[0] == 'g' :
      return '\033[;32m' + s[7:-3] + '\033[0m'
   for i in s :
     if i[0] == 'r' :
      return '\033[;31m' + s[5:-3] +'\033[0m'
   for i in s :
     if i[0] == 'b' :
      return '\033[;34m' + s[6:-3] + '\033[0m'
# ---------------------------------------------------
def highlight_words(s, words):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    if len(words) > 1 :
      for i in words :
        if i in s :
          s = s.replace(i, '\033[;103m' + i + '\033[0m')
      return s
    for i in words :
      if i in s :
        return s.replace(i, '\033[;103m' + i + '\033[0m')
      else :
        return s
    if words == [] :
      return s
# ---------------------------------------------------
def display_tag_file(filename):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    pass

6531803421: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display1.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 490, 'const': 562, 'code+const': 1052}
def red(s):
    return RED+s+RESET
# ---------------------------------------------------
def green(s):
    return GREEN+s+RESET
# ---------------------------------------------------
def blue(s):
    return BLUE+s+RESET
# ---------------------------------------------------
def highlight(s):
    return HIGHLIGHT+s+RESET
# ---------------------------------------------------
def color_text(s, color):
    color = color.lower()
    if color == 'red'  :
      return red(s) 
    elif color == 'green' :
      return green(s)
    elif color == 'blue' :
      return blue(s)
    else :
      return s
# ---------------------------------------------------
def color_tag(s):
    if '<red>' in s and '</>' in s: 
      return red(s[5:-3])
    elif '<green>' in s and '</>' in s :
      return green(s[7:-3])
    elif '<blue>' in s and '</>' in s : 
      return blue(s[6:-3])
    else : 
      return s
# ---------------------------------------------------
def highlight_words(s, words):
    for i in range (len(words)) :
      if words[i] in s :
        s = s.replace(words[i],highlight(words[i]))
    return s
# ---------------------------------------------------
def display_tag_file(filename):
  file = open(filename,'r',encoding='utf-8')
  for line in file:
    for i in range (line.count('</>')) :
      line = line.replace(line[line.find('<'):line.find('/>')+2],color_tag(line[line.find('<'):line.find('/>')+2])) 
    print(line,end='')

6531804021: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display1.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 1138, 'const': 985, 'code+const': 2123}
def red(s):
   # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
   ans=""
   ans= RED+s+RESET
   return ans
# ---------------------------------------------------
def green(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    ans=""
    ans= GREEN+s+RESET
    return ans
# ---------------------------------------------------
def blue(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    ans=""
    ans= BLUE+s+RESET
    return ans
# ---------------------------------------------------
def highlight(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    ans=""
    ans= HIGHLIGHT+s+RESET
    return ans
# ---------------------------------------------------
def color_text(s, color):
    if len(color)==3:
     if color[0]=="r" or color[0]=="R":
        if color[1]=="e" or color[1]=="E":
            if color[2]=="d" or color[2]=="D":
                ans=red(s)
            else:
                ans=s
        else:
            ans=s
     else:
          ans=s
    elif len(color) ==5:       
     if color[0]=="g" or color[0]=="G":
        if color[1]=="r" or color[1]=="R":
          if  color[2]=="e" or color[2]=="E":
              if color[3]=="e" or color[1]=="E":
                  if color[4]=="n" or color[4]=="N":
                      ans=green(s)
                  else:
                      ans=s
              else:
                  ans=s
          else:
               ans=s
        else:
            ans=s
     else:
          ans=s
    elif len(color)==4:
     if color[0]=="b" or color[0]=="B":
        if color[1]=="l" or color[1]=="L":
            if color[2]=="u" or color[2]=="U":
                if color[3]=="e" or color[3]=="E":
                    ans=blue(s)
                else:
                    ans=s
            else:
                 ans=s
        else:
             ans=s
     else:
        ans=s 
    else:
        ans=s
    return ans
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
# ---------------------------------------------------
def color_tag(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    colors=["red","green","blue"]
    x=""
    for ch in s:
        if ch=="<" or ch==">":
            x+="\\"
        else:
            x+=ch
    y=x.split("\\")
    a=[]
    b=[]
    c=[]
    z=[]
    for i in range(len(y)) :
        if y[i] in colors:
            a+=[i]
            c+=[y[i]]
        elif y[i]=="/":
            b+=[i]
        else:
            z+=[y[i]]
    word=[]        
    for j in range(len(a)):
        for k in range(len(y)):
            if int(a[j])< k <int(b[j]):
                word+=[y[k]]
    ans=""            
    for al in z:
        if len(word)!=0:
         for i in range(len(word)):
            if al in word:
              if al==word[i]:
                ans+=color_text(word[i], c[i])
                break
            else:
                ans+=al
                break
        else:
            ans+=al
    return ans       
# ---------------------------------------------------
def highlight_words(s, words):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    for c in words:
     if c in s:
        list_s=s.split(c)
        w=highlight(c)
        s=w.join(list_s)
    return s    
# ---------------------------------------------------
def display_tag_file(filename):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    file=open(filename,"r")
    for line in file:
      print(color_tag(line),end="")
    file.close()

6531805721: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_10.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display0.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 570, 'const': 488, 'code+const': 1058}
def red(s):
  out = RED+s+RESET
  return out
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
# ---------------------------------------------------
def green(s):
  out = GREEN+s+RESET
  return out
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
# ---------------------------------------------------
def blue(s):
  out = BLUE+s+RESET
  return out
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
# ---------------------------------------------------
def highlight(s):
  out = HIGHLIGHT+s+RESET
  return out
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
# ---------------------------------------------------
def color_text(s, color):
  t = color.lower()
  if t == 'red':
    return red(s)
  elif t == 'green':
    return green(s)
  elif t == 'blue':
    return blue(s)
  elif t == 'highlight':
    return highlight(s)
  else:
    return s
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
# ---------------------------------------------------
def color_tag(s):
  op = ['<red>','<green>','<blue>','</>']
  code = [RED,GREEN,BLUE,RESET]
  for i in range(4):
    s = s.replace(op[i],code[i])
  return s
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
# ---------------------------------------------------
def highlight_words(s, words):
  h = s.lower() ; start_index = [] ; stop_index = []
  w = [i.lower() for i in words]
  for n in w:
    i = 0
    while i < len(h):
      k = h.find(n,i,len(h))
      if k != -1:
        start_index.append(k)
        stop_index.append(k+len(n))
        i = k+len(n)
      else:
        break
  l = ''
  for i in range(len(s)):
    if i in start_index:
      l += (HIGHLIGHT+s[i])
    elif i in stop_index:
      l += (RESET+s[i])
    else:
      l += s[i]
  return l
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
# ---------------------------------------------------
def display_tag_file(filename):
  out = ''
  f = open(filename,'r',encoding='utf-8')
  for line in f:
    out += color_tag(line)
  return out
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน

6531806321: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display0.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 792, 'const': 856, 'code+const': 1648}
def red(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
  return RED+s+RESET
# ---------------------------------------------------
def green(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
  return GREEN+s+RESET
# ---------------------------------------------------
def blue(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
  return BLUE+s+RESET
# ---------------------------------------------------
def highlight(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
  return HIGHLIGHT+s+RESET
# ---------------------------------------------------
def color_text(s, color):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    if color.lower()=='red':
      return red(s)
    elif color.lower()=='blue':
      return blue(s)
    elif color.lower()=='green':
      return green(s)
    else:
      return s
# ---------------------------------------------------
def color_tag(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    i=0
    stat=str()
    f=str()
    while i!=len(s):
      if s[i:i+5]=='<red>':
        stat='red'
      elif s[i:i+7]=='<green>':
        stat='green'
      elif s[i:i+6]=='<blue>':
        stat='blue'
      elif s[i:i+3]=='</>':
        stat=str()
      if stat=='red':
        f+=red(s[i])
        i+=1
      elif stat=='green':
        f+=green(s[i])
        i+=1
      elif stat=='blue':
        f+=blue(s[i])
        i+=1
      else:
        f+=s[i]
        i+=1
    f=f.replace(red('<')+red('r')+red('e')+red('d')+red('>'),'').replace('</>','').replace(green('<')+green('g')+green('r')+green('e')+green('e')+green('n')+green('>'),'').replace(blue('<')+blue('b')+blue('l')+blue('u')+blue('e')+blue('>'),'')
    return f
# ---------------------------------------------------
def highlight_words(s, words):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    for e in words:
      s=s.replace(e,highlight(e))
    return s
# ---------------------------------------------------
def display_tag_file(filename):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    file=open(filename,'r',encoding='utf-8')
    l=list()
    l1=list()
    for line in file:
      l.append(line.strip())
    s=str()
    for e in l:
      if e!=l[-1]:
        s+=e+'\n'
      else:
        s+=e
    print(color_tag(s))
    file.close()

6531807021: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display0.0FileNotFoundError("No such file or directory: 'มหาจุฬาลงกรณ์-tag.txt'")
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 454, 'const': 1238, 'code+const': 1692}
def red(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return '\033[;31m' + s + '\033[0m'
# ---------------------------------------------------
def green(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return '\033[;32m' + s + '\033[0m'
# ---------------------------------------------------
def blue(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return '\033[;34m' + s + '\033[0m'
# ---------------------------------------------------
def highlight(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    return '\033[;103m' + s + '\033[0m'
# ---------------------------------------------------
def color_text(s,color):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
  if color.lower() == 'red':
    return '\033[;31m' + s + '\033[0m'
  if color.lower() == 'blue':
      return '\033[;34m' + s + '\033[0m'
  if color.lower() == 'green':
      return '\033[;32m' + s + '\033[0m'
  else:
      return s
# ---------------------------------------------------
def color_tag(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    a = s.find('>')
    b = s.find('<',a)
    c = s[a+1:b]
    if '<red>' in s:
      return '\033[;31m' + c + '\033[0m'
    if '<green>' in s:
      return '\033[;32m' + c + '\033[0m'
    if '<blue>' in s:
      return '\033[;34m' + c + '\033[0m'
# ---------------------------------------------------
def highlight_words(s, words):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    for i in words:
      s = s.replace(i,'\033[;103m' + i + '\033[0m' )
    return s
# ---------------------------------------------------
def display_tag_file(filename):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    file = open('มหาจุฬาลงกรณ์-tag.txt')
    for line in file:
      if '<red>' in line:
        line = line.replace('<red>','\033[;31m')
      if '<blue>' in line:
        line = line.replace('<blue>','\033[;34m')
      if '<green>' in line:
        line = line.replace('<green>','\033[;32m')
      if '</>' in line:
        line = line.replace('</>', '\033[0m')
      print(line,end='')
    file.close()

6531808621: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_21.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display1.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 890, 'const': 664, 'code+const': 1554}
def red(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
  return RED + s + RESET
# ---------------------------------------------------
def green(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
  return GREEN + s + RESET
# ---------------------------------------------------
def blue(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
  return BLUE + s + RESET
# ---------------------------------------------------
def highlight(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
  return HIGHLIGHT + s + RESET
# ---------------------------------------------------
def color_text(s, color):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    m = color.lower()
    if m == 'red':
      return(red(s))
    elif m == 'green':
      return(green(s))
    elif m == 'blue':
      return(blue(s))
    else:
      return(s)
# ---------------------------------------------------
def color_tag(s):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
    t = s.split('<')[1].split('>')[0] 
    m = s.split('<')[1].split('>')[1]
    if t == 'red':
      return(red(m))
    elif t == 'green':
      return(green(m))
    elif t == 'blue':
      return(blue(m))
# ---------------------------------------------------
def highlight_words(s, words):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
 lis = []
 b = s
 b2 = b
 if len(words) == 0:
  return(s)
 else:
  for i in words:
   m = i[0]
   i1 = i.lower()
   for e in range(len(s)):
     if  s[e:e+len(i)].lower() == i1:
       lis.append(b2[e:e+len(i)])
   for e in range(len(b)):
     if b[e:e+len(i)].lower() == i1:   
       b = b.replace(b[e:e+len(i)],b[e:e+len(i)].lower())     
   b = b.split(i1)
   for e in range(len(lis)):
    k = highlight(lis[e])
    b.insert(2*e+1,k)
   b = ''.join(b)
   lis = []
  return(b)  
# ---------------------------------------------------
def display_tag_file(filename):
    # ลบบรรทัด pass แล้วเขียนโค้ดของนิสิตแทน
 file = open(filename, 'r', encoding='utf-8')
 file = file.read()
 for i in range(file.count('/')):
  if '<' not in file:
     pass
  else:
   a = file.index('<')
   b= file.index('/')
   c= file.index('>')
   t = file[a+1:c]
   t = t.lower()
   if t == 'red':
     file = file.replace(file[a:b+2],red(file[c+1:b-1]))
   elif t == 'green':
     file = file.replace(file[a:b+2],green(file[c+1:b-1]))
   elif t == 'blue':
     file = file.replace(file[a:b+2],blue(file[c+1:b-1]))
 print(file)

6531810821: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_20.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display0.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 330, 'const': 535, 'code+const': 865}
def red(s):
    return RED + s + RESET
def green(s):
    return GREEN + s + RESET
def blue(s):
    return BLUE + s + RESET
def highlight(s):
    return HIGHLIGHT + s + RESET
def color_text(s, color):
    if color.lower() == "red" : return red(s)
    elif color.lower() == "green" : return green(s)
    elif color.lower() == "blue" : return blue(s)
    else : return s
def color_tag(s):
    s = s.replace("<red>", "\033[;31m")
    s = s.replace("<green>", "\033[;32m")
    s = s.replace("<blue>", "\033[;34m")
    s = s.replace("</>", "\033[0m")
    return s
def highlight_words(s, words):
    for i in words :
        s = s.replace(i, highlight(i))
    return s
def display_tag_file(filename):
    s = open(filename, 'r', encoding='utf-8')
    ans = ""
    for i in s :
        ans = ans + i + "\n"
    return color_tag(ans)

6532186021: HW04
testfuncscerrstu_stdoutstu_keptstu_fout
test_highlight_11.0
['\x1b[;103mabc\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mabc\x1b[0mabbcbf\x1b[;103mfg\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_highlight_21.0
['\x1b[;103maBC\x1b[0mde\x1b[;103mfg\x1b[0m\x1b[;103mAbc\x1b[0mAbbcbf\x1b[;103mfG\x1b[0mcd\x1b[;103mabc\x1b[0maa\x1b[;103mabc\x1b[0m']
test_display1.0
abcrrrpkk
defgggocr
xyzbbbabc
abcrrrpfgggorrzbbbabc
[]
bytecount: {'code': 804, 'const': 596, 'code+const': 1400}
def red(s):
    return RED+s+RESET
# ---------------------------------------------------
def green(s):
    return GREEN+s+RESET
# ---------------------------------------------------
def blue(s):
    return BLUE+s+RESET
# ---------------------------------------------------
def highlight(s):
    return HIGHLIGHT+s+RESET
# ---------------------------------------------------
def color_text(s, color):
    color = color.upper()
    if color == "BLUE":
        return blue(s)
    elif color == "GREEN":
        return green(s)
    elif color == "RED":
        return red(s)
    else:
        return s
# ---------------------------------------------------
def color_tag(s):
    i = 0
    while True:
        start_i = s.find('<red>',i)
        if start_i == -1:
            break
        else:
            stop_i = s.find('</>',start_i)
            if stop_i == -1:
                break
            s = s[:start_i]+color_text(s[start_i+5:stop_i],'red')+s[stop_i+3:]
            i = stop_i+5
    i = 0
    while True:
        start_i = s.find('<blue>',i)
        if start_i == -1:
            break
        else:
            stop_i = s.find('</>',start_i)
            if stop_i == -1:
                break
            s = s[:start_i]+color_text(s[start_i+6:stop_i],'blue')+s[stop_i+3:]
            i = stop_i+4
    i = 0
    while True:
        start_i = s.find('<green>',i)
        if start_i == -1:
            break
        else:
            stop_i = s.find('</>',start_i)
            if stop_i == -1:
                break
            s = s[:start_i]+color_text(s[start_i+7:stop_i],'green')+s[stop_i+3:]
            i = stop_i+3
    return s
# ---------------------------------------------------
def highlight_words(s, words):
    s_upper = s.upper()
    for e in words:
        e = e.upper()
        i = 0
        while True:
            start_i = s_upper.find(e,i)
            if start_i == -1:
                break
            else:
                s = s[:start_i]+highlight(s[start_i:start_i+len(e)])+s[start_i+len(e):]
                s_upper = s_upper[:start_i]+highlight(s_upper[start_i:start_i+len(e)])+s_upper[start_i+len(e):]
                i = start_i+len(HIGHLIGHT)+len(e)+len(RESET)
    return s
# ---------------------------------------------------
def display_tag_file(filename):
    file = open(filename, 'r', encoding='utf-8')
    string = ''
    for e in file:
        string += e
    string = color_tag(string)
    print(string)
    file.close()