發表文章

林苡嫻python, input, str, float

圖片
程式碼 from math import * def f(r): print(f"賴清德輸入的半徑{r} ") print(f"圓面積: {pi*r*r} ") print(f"球體積: {pi*r*r*r*4/3}") print(f"球表面積:{pi*r*r*4}") def abc(r): print("賴清德輸入的半徑 " + str(r)) print("圓面積: "+str(pi*r*r)) print("圓周長: "+str(pi*r*2)) print("球體積: "+str(pi*r*r*r*4/3)) print("球表面積:"+str(pi*r*r*4)) def tri(z): print("賴清德輸入的角度 " + str(y)) print("正弦sin "+str(sin(z))) print("餘弦cos "+str(cos(z))) def g(z): print(f"正弦sin {sin(z)}") print(f"餘弦cos {cos(z)}") def group(r, t): abc(r) tri(t) f(r) g(t) r = float(input("輸入半徑: ")) y = float(input("輸入角度360度單位: ")) t = y/180*pi #將360較度轉成弧度180=pi group(r,t) 截圖 上課影片

林苡嫻python輸入import數學math函式庫define定義function函數

圖片
w3cchools程式碼 from math import * #林苡嫻從math函式庫輸入所有函數 r=1 #半徑 def f(r): #定義函數 define 名稱(參數),以下相同縮排都是 print("圓面積pi r*r: "+str(pi*r*r)) print("圓周長pi r*2: "+str(pi*r*2)) print("球體積pi r*r*r*4/3:"+str(pi*r*r*r*4/3)) print("球表面積pi r*r*4: "+str(pi*r*r*4)) def g(angle): print("正弦sin:"+str(sin(angle))) print("餘弦cos:"+str(cos(angle))) def h(x,y): #用在模組化你的程式碼 f(x) g(y) print("林苡嫻:自訂函數h呼叫f,g再呼叫內建pi,sin,cos\n") h(1,pi/6) w3cchools程式碼截圖 VS code程式碼 from math import * #林苡嫻從math函式庫輸入所有函數 from tkinter import * def f(r): #定義函數 define 名稱(參數),以下相同縮排都是 print("圓面積pi r*r: "+str(pi*r*r)) print("圓周長pi r*2: "+str(pi*r*2)) print("球體積pi r*r*r*4/3:"+str(pi*r*r*r*4/3)) print("球表面積pi r*r*4: "+str(pi*r*r*4)) def g(angle): print("正弦sin:"+str(sin(angle))) print("餘弦cos:"+str(cos(angle))) def h(x,y): #用在模組化你的程式碼 f(x) g(y) print("劉任昌:自訂函數h呼叫f,g再呼叫內建p...

林苡嫻Python類別class函數function

圖片
VS code編輯類別 VS code程式碼 from tkinter import * #從函式庫 tkinter 輸入所有 * 方法 from math import * #從函式庫 math 輸入所有 * 方法 class 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.append(...

林苡嫻VSCode編輯Python, tkinter建構Button,Lable

圖片
程式碼 from tkinter import * #從函式庫 tkinter 輸入所有 * 方法 # math只用三個沒必要輸入所有*, math.pi比 pi 更清楚 import math #連線去找函式庫 t = (3,4,5,6,7,8,9,10,11,12,16,20)#宣告一元組tuple(...) tk = Tk() tk.title("林苡嫻視窗使用者介面GUI") canvas = Canvas(tk, width=800, height=500) canvas.pack() def show(event): #定義由事件event(按鈕選單)呼叫的函數show cx = 110 #宣告圓中心座標cx, cy半徑cr cy = 210 cr = 100 x, y =[],[] #宣告二陣列[...] k = s.get() #取得 ge t按鈕選單的選擇變數 u = 2 * math.pi / k #使用模組 math 圓周率 pi for i in range(k): x.append(cx + cr*math.cos(i*u)) #加入陣列的元素 y.append(cy + cr*math.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], fill="blue",width=5) canvas.create_line(x[k-1], y[k-1], x[0], y[0], fill="blue",width=5) #可考慮增加width寬度,fill顏色 def diagonal(): cx, cy, cr = 500, 210, 150 #宣告圓中心座標cx, cy半徑c...

林苡嫻VS code python 圖型編輯

圖片
期中考複習 # 集合{},字典{key:value,},元組(),清單或陣列[] p = ("台積電", "鴻海", "聯發科") r = {"台積電", "鴻海", "聯發科"} s = ["台積電", "鴻海", "聯發科"] t = ["中華電", "台塑化", "台達電"] d= {2330:"台積電",2317:"鴻海",2454:"聯發科"} u = s v = s.copy() s = s.extend(t) print(u) print(v) print(len(d)) i = 0 for a in p: #然後嘗試取代p為r,s,t,u i = i+1 print("台灣第" + str(i) + "大的公司是") print(" " + a) 期中考複習截圖 VS code 邊多邊形程式碼 from tkinter import * #從函式庫 tkinter 輸入所有 * 方法 from math import * #從函式庫 math 輸入所有 * 方法 t = (3,4,5,6,7,8,9,10,11,12,16,20) #宣告一元組tuple(...) tk = Tk() tk.title("林苡嫻視窗使用者介面GUI") 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() ...

林苡嫻陣列,append,copy,w3schools

圖片
w3schools陣列截圖 w3schools陣列程式碼 #劉任昌w3schools練習 #for x in 'Takming gold': #迴圈逐字字元 # print("字母: %s" % x) fruits = ['台積電', '鴻海', '聯發科'] for x in fruits: # 迴圈印出元素 print ("當前公司: %s"% x) print ("append") #append在末尾增加 fruits.append("中華電") #append接元素 print(fruits) print("移除所有元素clear") fruits.clear() #Removes all the elements from the list print(fruits) fruits = ['台積電', '鴻海', '聯發科',"中華電"] print(fruits) pig = fruits.copy() print("輸出pig用copy方法" + str(pig)) print("使用copy和直接賦予值 pig = fruits有何不同? ") dog = fruits print("輸出dog直接=" + str(dog)) print("fruits.extend(pig)") fruits.extend(pig) #extend接陣列或清單 print(fruits) fruits.extend(['台塑化','台達電','富邦金']) print(fruits) #print("幾個台積電? " + str(fruits.count("台積電))) print(fruits.index("富邦金")) fruits.insert(10,"國泰金") print(fruits) print...

林苡嫻 集合{},清單[],元組(),字典{key:value}

圖片
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 a...