發表文章

吳尚豪類別class __init__(self, 其他參數)

圖片
w3schools類別class class Person: #定義類別class稱為Person def __init__(self, name, age): #起始屬性函數一律稱__init__ self.name = name self.age = age def myfunc(self): print("嗐,我的\n名字是" + self.name) #字串中\n換列 print("嗐,我的") print("名字是" + self.name) p1 = Person("吳尚豪", 36) #利用類別建構物件(實例) p1.myfunc() 多邊形類別class from tkinter import * #從函式庫 tkinter 輸入所有 * 方法 import math #從函式庫 math 輸入所有 * 方法 from time import * from random import * 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 * math.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*math.cos(i*self.u)) se...

吳尚豪類別,必須有 兩底線init兩底線的起始initiate函數

圖片
class Person: #建立類別,必須有 兩底線init兩底線的起始initiate函數   def __init__(self, name, age):     self.name = name     self.age = age   def myfunc(self):     print("嗨!我的")     print("名子是 " + self.name)     print("嗨!我的\n名子是 " + self.name) #字串中\n換列      p1 = Person("吳尚豪", 36) p1.myfunc() print("印出p1.name: " + p1.name)  from tkinter import * #從函式庫 tkinter 輸入所有 * 方法 import math     #從函式庫 math 輸入所有 * 方法 from time import * from random import * 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 * math.pi / self .s #使用模組 math 圓周率...

吳尚豪python時間函式time.sleep

圖片
  from tkinter import * #從函式庫 tkinter 輸入所有 * 方法 from math import *     #從函式庫 math 輸入所有 * 方法 import 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 ):          ...

吳尚豪python, input, str, float

圖片
VS code編輯環境截圖   VS code程式碼 from math import * 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 group(r, t):   abc(r)   tri(t) r = float(input("輸入半徑: ")) y = float(input("輸入角度360度單位: ")) t = y/180*pi group(r,t) 說明影片

吳尚豪python輸入import數學math函式庫define定義function函數

圖片
import math #吳尚豪輸入math函式庫 def abc(r): #定義函數abc   print("園面積: " + str(math.pi *r *r))   print("園周長: " + str(math.pi *r *2))   print("球體積: " + str(math.pi *r *r *r *4 /3))   print("球表面積: " + str(math.pi *r *r *4)) def tri(z):   print("正弦sin " +str(math.sin(z)))   print("餘弦cos " +str(math.cos(z))) r = 1 #半徑 abc(r) #呼叫abc函數,得面積等結果 tri(math.pi/6) #30度=/6 from math import import  math import

吳尚豪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):                                 #類別的方法 ...
圖片
吳尚豪VSCode自訂方法canvas.delete('all')建構Button #原來240單元程式碼如下 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 = 1000 , height = 500 ) canvas.pack() def show ( event ):                         #定義由事件event(按鈕選單)呼叫的函數show    cx, cy, cr = 110 , 210 , 100           #宣告圓中心座標cx, cy半徑cr    x, y = [],[]                           #宣告二陣列[...]    k = s.get()                           #取得 ge t按鈕選單的選擇變數    u = 2 * pi / k                       #使用模組 math 圓周率 pi     for i in range (k)...