發表文章

目前顯示的是 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"] #將工作表python稱為sheet 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"].value #將A1的年月日存在x sheet["A1"] = "劉任昌" + x sheet["F1"] = "波段H" sheet["G1"] = "波段L" sheet["H1"] = "部位" sheet["I1"] = "損益" sheet["F2"], sheet["G2"], sheet["H2"], sheet["I2"]=sheet["C2"].value, sheet["D2"].value, 0, 0 for row in sheet.iter_rows(min_row=1, max_row=3, min_col=1, max_col=9, values_only=True): print(row) book.save(...

劉任昌python import openpyxl 處理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. 列出工作表所有內容") #sheet["F1"], sheet["G1"], sheet["H1"], sheet["I1"]="波段H","波段L","部位","損益" #sheet["F2"], sheet["G2"], sheet["H2"], sheet["I2"]=sheet["C2"].value, sheet["D2"].value, 0, 0 #for row in sheet.iter_rows(min_row=1, max_row=3, min_col=1, max_col=9, values_only=True): # print(row) #book.save() from tkinter import * import pygame root = Tk() root.title("劉任昌") root.geometry("500x400...

劉任昌python math random

圖片
w3schools學習python math random函式庫 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程式 影片 Bro Code程式碼 https://www.youtube.com/watch?v=bfRwxS5d0SI # 劉任昌2023年5月12日修改自Bro Code YT影片 from tkinter import *#輸入tkinter繪圖程式庫 import random #輸入亂數程式庫 GAME_WIDTH = 1000 GAME_HEIGHT = 600 SPEED = 300 SPACE_SIZE = 50 BODY_PARTS = 3 #蛇長度 SNAKE_COLOR = "yellow" #蛇顏色green FOOD_COLOR = "white" #雞蛋顏色白色 BACKGROUND_COLOR = "#000000"#背景黑色 class Snake: #定義類別Snake def __init__(self): self.body_size = BODY_PARTS #蛇長度 self.coordinates = [] self.squares = [] for i in range(0, BODY_PARTS): self.coordinates.append([0, 0]) for x, ...

劉任昌python視窗使用者介面GUI類別class建構正多邊形或星形

圖片
#劉任昌教python設窗程式設計 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()) ...