發表文章

吳泊諺python時間函式time.sleep

圖片
from tkinter import * #從函式庫 tkinter 輸入所有 * 方法 from math import * #從函式庫 math 輸入所有 * 方法 import time #輸入time class Regular: def __init__(self, cx, cy, cr, s, t, c, w): #類別共同的設定必然 def __init__ initiate發起 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) time.sleep(0.5) #睡覺一秒 tk.update() def show(): #畫圖 define自訂函數 p...

吳泊諺python輸入import數學math函式庫define定義function函數

圖片
from math import * #吳泊諺從math輸入所有函式 # import math #吳泊諺輸入math函式庫 def abc(r): #定義函數abc 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("正弦sin "+str(sin(z))) print("餘弦cos "+str(cos(z))) def group(r, t): abc(r) tri(t) r , t = 1, pi/3 #半徑, 60度=pi/3 group(r,t)

吳泊諺python陣列array

圖片
w3shools陣列截圖 w3shools陣列程式碼 #吳泊諺拷貝自 201單元 """for x in 'Takming': #迴圈逐字元印出 print("字母: %s" % x)三引號框起註解 """ fruits = ['台積電', '鴻海', '聯發科'] #台灣市場價值最高的三公司 for x in fruits: # print ("公司: %s" % x) print(fruits) fruits.append("中華電") print("使用append") print(fruits) fruits.clear() print("使用clear") print(fruits) fruits = ['台積電', '鴻海', '聯發科', '中華電'] chicken = fruits.copy() #和 chicken = fruits 有何不同? print(chicken) fruits.append("中華電") print(fruits.count("中華電")) print(fruits.count("台積電")) for x in fruits: print(x) if x == "中華電": #判斷式是否banana print('I hate 中華電.') if x == "聯發科": #判斷式是否cherry print('I like cherry.') if x == "鴻海": #判斷式是否apple print('You are my sweet apple.') #體會到只要我有耐心與興趣,我也可以當一個專業的程式開發人員 w3shool陣列方法Array Methods Array ...

吳泊諺Python字典Dictionaries

圖片
w3schools截圖 w3schools練習程式碼 #字典 keys:values, 吳泊諺 #w3schools原來 字串:字串,改成 整數:字串 a = { #市場價值最大的五家公司 2330: "台積電", 2317: "鴻海", 2454: "聯發科", 2412: "中華電", 6505: "台塑化" } print(a) print(a[6505]) print(a.get(2330))#功能同 a[2330] print(a.keys()) #keys()方法列出key搜尋鍵 print(a.values()) #keys()方法列出values值 b = a.copy() print("列出b " + str(b)) print(b[2317]) print(b.clear()) a.update({2308: "台達電"}) print(a.values()) print("用迴圈列出字典a的所有值") for t in a: print(a[t]) 字典方法Dictionary Methods Dictionary Methods Python has a set of built-in methods that you can use on dictionaries. Method Description clear() Removes all the elements 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 each key value pair keys() Returns a list containing the dictionary'...

吳泊諺python,print,input字串[::-1]

圖片
程式碼 #吳泊諺的第一個python程式2023/2/20 print("你在跟我哈拉嗎?") #python輸出比Java簡單太多 a ="你在跟我哈拉,狗吃屎" #python指令結尾不需要;分號 b ="貓抓鼠,師父開勞斯萊斯" #python字串單引雙引號都可 print(a) print(b) c =a[1:5:] #取字串a的第1到5(不含),從0開始 print(c) c =a[::-1] print(c) 心得 Java輸出System.out.println():

吳泊諺學會Java也學會JavaScript,input,text,button,getValueByld

圖片
輸入資料,JavaScript執行,輸出 輸入字串: 劉任昌194影片 劉任昌196影片解說這個作業

吳泊諺Java輸入套件import package掃描器Scanner

圖片
import java.util.Scanner; /*開啟套件package util=utility用途,Scanner掃描器*/ /*吳泊諺utility industry=公用事業產業,電力,自來水,效用=utility */ class MyClass { public static void main(String[] args) { String a, b=""; Scanner myObj = new Scanner(System.in); //輸入到掃描Scanner物件 System.out.print("輸入: "); a = myObj.nextLine(); /*輸入文字nextLine到變數a */ System.out.println("長度: " + a.length()); for (int i = 0; i