發表文章

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

葉可棠python集合set元組tuple清單或串列list迴圈輸出str,int

圖片
w3schools截圖 w3schools程式碼 #葉可棠 集合{},清單[],元組(),字典{key:value} s = {"台積電", "鴻海", "聯發科", "中華電", "台塑化"} t = ("台積電", "鴻海", "聯發科", "中華電", "台塑化") list = ["台積電", "鴻海", "聯發科"] d = {2330:"台積電", 2317:"鴻海", 2454:"聯發科"} print("s型態" + str(type(s))) print("t型態" + str(type(t))) print("d型態" + str(type(d))) print("t型態" + str(type(list))) #字串與字串+ i = 0 for a in t: i = i + 1 print("台灣市場價格第" + str(i) + "大公司是") print(" " + a) print("聯發科的位置" + str(t.index("聯發科"))) '''python大區塊的註解,前後用三個引號 str 轉成字串 int 轉成數字''' w3schools元組tuples的方法 Python has two built-in methods that you can use on tuples. Method Description count() Returns the number of times a specified value occurs in a tuple index() Searches the tuple for ...

葉可棠python陣列array

圖片
w3schools截圖 w3schools程式碼 #葉可棠陣列 #for x in 'Takming gold': # 第一個實例 # print("當前字母: %s" % x) fruits = ['台積電', '鴻海', '聯發科'] for x in fruits: # 第二個實例 print ("最大公司水果: %s" % x) print ("練習陣列的11個內建方法") fruits.append("中華電") #append加元素 fruits.clear() fruits = ['台積電', '鴻海', '聯發科', '中華電'] print(fruits) pig = fruits.copy() print("輸出pig=fruits.copy()結果" + str(pig)) cat = fruits print("輸出cat=fruits的結果"+str(cat)) fruits.extend(fruits) #extend尾巴+陣列, append加元素 print("extend的 "+str(fruits)) print("copy 的 "+str(pig)) print(" = 的 "+str(cat)) print(fruits.count("台積電")) fruits.insert(1,"富邦金") print(fruits) print(fruits.index("富邦金")) fruits.reverse() print(fruits) fruits.sort() print(fruits) fruits.remove("富邦金") #拿走富邦金 print(fruits) fruits.pop(2) #拿走012的2 print(fruits) #體會到只要我有耐心與興趣,我也可以當一個專業的程式開...

葉可棠期中考VS Code編輯Python

圖片
from tkinter import * #從函式庫 tkinter 輸入所有 * 方法 from math import * #從函式庫 math 輸入所有 * 方法 t = (3,4,5,6,7,8,9,10,11,12,16,20,32) #宣告一元組tuple(...) tk = Tk() tk.title("劉任昌圖形使用者介面GUI=Graphical Unser Interface") canvas = Canvas(tk, width=500, height=500) canvas.pack() def show(event): #定義由事件event(按鈕選單)呼叫的函數show cx, cy, cr = 210, 210, 200 #宣告圓中心座標cx, cy半徑cr x, y =[],[] #宣告二陣列[...] k = s.get() #取得 ge t按鈕選單的選擇變數 u = 2 * pi / k #使用模組 math 圓周率 pi for i in range(k): x.append(cx + cr*cos(i*u)) #加入陣列的元素 y.append(cy + cr*sin(i*u)) #使用模組 math 三角函數cos, sin for i in range(k-1): canvas.create_line(x[i], y[i], x[i+1], y[i+1]) canvas.create_line(x[k-1], y[k-1], x[0], y[0]) #可考慮增加width寬度,fill顏色 def diagonal(): cx, cy, cr = 210, 210, 200 #宣告圓中心座標cx, cy半徑cr外來學繼承 inheritance x, y =[],[] #宣告二陣列[......