發表文章

葉可棠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 =[],[] #宣告二陣列[......

葉可棠python字典

圖片
h1{background-color: green; opacity: 0.3; color: blue; padding: 20px;} pre{border: solid 3px red;} w3schools截圖 程式碼 a = { #台灣股票市場價值最大,劉任昌python 2330: "台積電", 2317: "鴻海", 2454: "聯發科", 2412: '中華電'} print(a) print("用迴圈印出所有值") for t in a: print(a[t] +" 用get()方法 " + a.get(t)) a.update({1108:"幸福"}) print(a) a.popitem() print(a) a.update({6505:"台塑化"}) a.update({2308:"台達電"}) print(a.keys()) print("練習values方法") print(a.values()) print("練習items方法") print(a.items()) w3schools字典方法 確保在</h1>之後貼上才先在html模式放一個標記a Python has a set of built-in methods that you can use on dictionaries. Method 方法 Description說明 clear() 移除字典的Removes all the elements項目(items) from the dictionary copy() Returns a copy of the dictionary fromkeys() Returns a dictionary with the specified keys and value get() Returns the value of the specified key items() Returns a list containing a tuple for e...

葉可棠SVG與CANVAS

圖片
w3schools練習SVG w3schools練習canvas 心得 canvas帆布 ol=office lady, 這裡是 ordered list順序的清單 標楷體命令「font-family: DFKai-sb」 幕前排版系統word,編輯網頁的撰寫模式,幕後排版系統控制你的命令 教學影片 維基百科SVG 維基百科canvas Sorry, your browser does not support inline SVG.

w3schools字串slicing[::],str,len

圖片
b = "我男友是個大帥哥" #python字串單或雙引號都可 # 0 1 2 3 4 # -6-5-4-3-2-1 print("字串長度:"+str(len(b)))#相同字串型態才能串接 print("反過來:"+b[::-1]) print(b[:3]) #b字串的0,1,2 print(b[-4:-1]) print(b[-8:-4]) x='火鍋' y=9999 myorder="我希望{2}陪我去吃{0}他付錢{1}." print(myorder.format(x, y, b)) # format的參數 0 1 2 字串的方法列表 Method Description capitalize() Converts the first character to upper case casefold() Converts string into lower case center() Returns a centered string count() Returns the number of times a specified value occurs in a string encode() Returns an encoded version of the string endswith() Returns true if the string ends with the specified value expandtabs() Sets the tab size of the string find() Searches the string for a specified value and returns the position of where it was found format() Formats specified values in a string format_map() Formats specified values in a string index() Searches the string for a specified value and returns the position...

D11117310葉可棠JavaScript將輸入的字串顛倒輸出

圖片
網頁介面 葉可棠輸入字串: 程式碼 <p>葉可棠輸入字串:<input id="in" len="40" type="text" /></p> <p><input onclick="f()" type="button" value="執行JavaScript" /></p> <p id="out"></p> <script> function f(){   var a = document.getElementById("in").value;/*取得id=in的文字*/   var b ="原字串:" + a + "<br>長度是:" + a.length + ",反串是: ";   var c = "";   for (var i = 0; i < a.length; i++)     c = a.slice(i,i+1) + c ;   b = b +"<front size=7>" + c + "</front>";   document.getElementById("out").innerHTML = b; } </script> vs CODE編輯JAVA import java.util.Scanner; /*開啟套件package util=utility用途,Scanner掃描器*/ /*葉可棠utility industry=公用事業產業,電力,自來水,效用=utility */ class MyClass { public static void main(String[] args) { String a, b=""; /*定義字串a,b */ Scanner...