發表文章

目前顯示的是 5月, 2023的文章

許閔為Python處理excel檔案

圖片
import openpyxl #許閔為輸入import openpyxl處理EXCEL的函式庫 book = openpyxl.load_workbook(r'wb.xlsx') #開啟EXCEL工作簿wb.xlsx print("1. 列出所有工作表名稱") sheetNames=book.sheetnames #所有工作表的集合 for name in sheetNames: print(name) print("2. 針對特定工作表, 列出前面數列") #sheet = book["python"] #for row in sheet.iter_rows(min_row=1, max_row=3, min_col=1, max_col=5, values_only=True): # print(row) print("3. 列出工作表所有內容") x = sheet["A1"] = #將A1的年月日存在X Sheet["A1"] = "許閔為" + X Sheet["F1"] ="波段H" Sheet["G1"] ="波段L" Sheet["H1"] ="部位" Sheet["I1"] ="損益" #sheet["F1"], sheet["G1"], sheet["H1"], sheet["I1"]="波段H","波段L","部位","損益" #sheet["F2"], sheet["G2"], sheet["H2"], sheet["I2"]=sheet["C2"].value, sheet["D2"].value...

衍生性金融商品的定價

圖片
import math #許閔為 輸入數學函式庫 import random #輸入亂數資料庫 x = math.sqrt(2) print(x) #大樂透是49個號碼開出六個 for i in range(6): x = random.randint(1,49) print("開出的第 " + str(i+1) + " 個號碼: " + str(x)) #str是將數字轉成字串string w3schools學習python math random截圖 亂數函數主要用在蒙地卡羅模擬分析,用於衍生性金融商品的訂價。 貪吃蛇的python程式 影片      

許閔為python視窗使用者介面GUI類別CLASS建構正多邊形或星行

圖片
  from tkinter import * #從函式庫 tkinter 輸入所有 * 方法 from math import * #從函式庫 math 輸入所有 * 方法 class Regular: #定義類別Regular正多邊形或星型 def __init__(self, cx, cy, cr, s, t, c, w): #類別共同的設定 self.cx, self.cy, self.cr = cx, cy, cr #取得中心座標cx, cy, 半徑cr self.s, self.t = s, t #取得邊角數目s,t尖銳程度,取代原來的k = s.get() self.c, self.w = c, w #取得顏色c,寬度w self.u = 2 * pi / self.s #使用模組 math 圓周率 pi self.x, self.y = [], [] for i in range( int(self.s * 1.5)): self.x.append(self.cx + self.cr*cos(i*self.u)) self.y.append(self.cy + self.cr*sin(i*self.u)) def draw(self): #類別的方法 for i in range( int(self.s * 1.5) - self.t): canvas.create_line(self.x[i], self.y[i], self.x[i + self.t], self.y[i + self.t], fill = self.c, width = self.w) def show(): #畫圖 poly = Regular(cx.get(), cy.get(), cr.get(), s.get(), t.get(), c.get(), w.get()) polyList.ap...