20161209 - s40523143/2016fallcp_hw GitHub Wiki

<script type="text/python3"> from browser import document as doc from browser import html # 利用 document 根據 div 標註 id 設為 container 變數 container = doc['temperature']

因為此函式與滑鼠互動, 需要 event 當作輸入

def convTemp(event): mystring = "" cdegree = input("請輸入攝氏溫度:") fdegree = float(cdegree)*9/5 + 32 output_string = "攝氏 " + str(cdegree) + "度=華氏 " + str(fdegree) + "度" + html.BR() container <= output_string

與 id 為 'w13-1' 對應的 button 綁定, 且滑鼠 click 後, 呼叫 convTemp 函式執行

doc['w13-1'].bind('click',convTemp) </script> 取攝氏溫度, 轉為華氏溫度

⚠️ **GitHub.com Fallback** ⚠️