呂庭娟

 class Financial: 

    def __init__(self, number, q, a, b, c, d, ans): 

        self.number, self.q, self.ans = number, q, ans

        self.a, self.b, self.c, self.d = a, b, c, d

f = open('C:/Users/user/Downloads/金融常識.txt','r',encoding='utf-8')

read = f.readlines() #read = f.read()

f.close()

List = []

Answer=(4,4,3,4,3,2,3,3,4,2,4,4,4,3,4,2,3,1,1,2,1,2,3,3,1,3,4,4,3,4,1,4,3,2,4,2,2,3,2,4,1,4,1,1,4,3,1,2,4,1,2,1,4,4,4,1,4,2,1,3,3,1,4,4,3,2,2,2,4,4,1,3,3,1,2,4,1,3,4,4,2,4,4,3,4,1,3,2,3,2,3,2,2,2,4,4,4,1,1,2,2,4,4,1,4,1,4,4,4,2,1,1,2,1,2,1,2,2,3,3,3,4,2,1,1,1,1,2,2,1,4,4,4,4,4,4,4,3,4,4,1,1,2,2,3,4,4,3,1,4,2,3,3,2,1,3,4,4,2,4,1,1,3,3,2,2,3,1,2,1,4,3,3,2,2,2,1,4,2,4,3,3,3,1,3,3,2,3,3,1,4,4,3,2,4,2,2,4,1,1,1,3,1,3,2,2,3,4,4,3,2,2,1,2,4,1,1,2,2,1,1,1,3,1,2,2,2,1,1,4,1,3,1,1,1,1,1,3,1,2,3,3,3,2,4,3,3,3,1,2,4,2,3,3,1,4,2,3,3,3,4,1,2,3,2,3,4,2,3,4,4,1,2,4,3,4,4,2,2,3,1,4,3,4,2,1,2,3,2,4,2,1,3,4,1,2,1,1,4,1,2,4,1,4,3,4,4,2,2,1,1,2,3,4,3,3,1,3,1,4,4,3,2,4,4,2,1,1,4,1,1,2,3,2,3,3,4,2,2,4,3,3,3,2,1,1,2,2,4,1,4,1,3,1,1,4,1,4,4,3,1,4,3,3,2,1,1,4,2,4,2,4,1,1,4,1,3,1,2,4,1,1,4,1,3,1,3,4,1,4,2,3,1,3,2,3,3,3,4,2,3,4,3,1,4,1,3,3,4,4,4,4,1,2,3,1,3,3,3,1,3,4,1,3,1,4,1,3,2,4,4,3,1,1,4,2,1,3,1,2,2,1,1,4,3,2,3,4,1,4,1,1,4,2,1,2,1,2,4,3,1,3,3,2,4,3,1,2,1,3,3,3,1,4,3,1,3,2,3,1,3,1,4,1,1,4,4,2,3,1,4,4,3,4,1,3,4,2,3,4,4,2,3,1)

nList, nAnswer = len(read), len(Answer) 

if nList != nAnswer: print('題目長度 ', nList, ' 與答案長度 ', nAnswer,' 不同!')

for i in range( nList ):

    a1 = read[i].find('(1)')

    b2 = read[i].find('(2)')

    c3 = read[i].find('(3)')

    d4 = read[i].find('(4)')

    q = read[i][:a1]

    a = '(1) ' + read[i][a1 + 3 : b2]

    b = '(2) ' + read[i][b2 + 3 : c3]

    c = '(3) ' + read[i][c3 + 3 : d4]

    d = '(4) ' + read[i][d4 + 3 : -1]

    List.append( Financial( i+1, q, a, b, c, d, str(Answer[i])) )

outputList = []

style ='<STYLE>.Chosen{BORDER: 2PX SOLID red;}.Right{BACKGROUND-COLOR: LIGHTGREEN;}</STYLE>'

javascript = '<SCRIPT>function Check (order, reply, answer){const element = document.getElementById("q"+order);if (reply == "答") return; else{element.children[reply-1].classList.add("Chosen");if ( reply == answer){element.children[reply-1].classList.add("Right");}}}</SCRIPT>'

outputList.append(style)

outputList.append(javascript)

title = '<H1>學術舞弊獵人Python撰寫金融常識測驗網頁</H1>'

outputList.append(title)

outputList.append('<OL TYPE="1">')

tmp0 = "<LI class='monkey'><SELECT ONCHANGE='Check(this.id, this.value, "

tmp1 = ")' ID='"

tmp2 = "'><OPTION>答</OPTION><OPTION>1</OPTION><OPTION>2</OPTION><OPTION>3</OPTION><OPTION>4</OPTION></SELECT>\n"

tmp3 = "<OL TYPE='1' ID='q"

tmp4 = "'>\n<LI>"

tmp5 = "</LI>\n<LI>"

tmp6 = "</LI></OL></LI>"

for i in range(nList): #range(nList)

    tmp = tmp0 + List[i].ans + tmp1 + str(List[i].number).zfill(3) + tmp2

    tmp += List[i].q + tmp3 + str(List[i].number).zfill(3) + tmp4 

    tmp += List[i].a + tmp5 

    tmp += List[i].b + tmp5

    tmp += List[i].c + tmp5

    tmp += List[i].d + tmp6

    outputList.append(tmp)

outputList.append('</OL>')  

f = open('呂庭娟.HTML','w',encoding='utf-8')

for item in outputList: #打開一個檔案名稱金融常識.HTML寫入資料

    print(item, file = f) #我不再當print在螢幕的學生而是產出檔案的專業開發人才

#    print(item)#上週產生APP必須利用繪圖套件tkinter被瀏覽器取代因為我們產出網頁

f.close()

留言

  1. 914在撰寫模式下貼上程式碼,不是結果,記得問老師如何修正。https://lutingjuan.blogspot.com/2026/09/blog-post.html
    911在撰寫模式下貼上導致PRE STYLE="BORDER:5PX RED SOLID"沒有作用,記得問老師或同學如何訂正。https://lutingjuan.blogspot.com/2026/09/pythonordchrunicode.html

    回覆刪除
  2. https://lutingjuan.blogspot.com/2026/10/blog-post.html

    回覆刪除

張貼留言

這個網誌中的熱門文章

呂庭娟w3schools字串str串列list集合set字典dict元組tuple 10月 04, 2026

呂庭娟雙迴圈