2022年5月29日 星期日

Topic41:Python學習9_用Python玩國中數學

 

重點0-7運用元宇宙工具,打造自己的虛擬展間

網站    https://youtu.be/_GSx0Lq5PuE

重點0-6性平小學堂

有獎徵答網站    https://www.gender.ey.gov.tw/School/Default.aspx

重點0-52022「億」鳴驚人雙重送

抽獎辦法網站    https://cooc.tp.edu.tw/news/305  活動計畫海報

重點0-4臺北疫苗通行證抽獎活動辦法

抽獎辦法網站    https://cooc.tp.edu.tw/news/306  活動辦法海報

重點0-3FQ等你來挑戰-得獎名單

FQ獲獎名單    http://www.ymsh.tp.edu.tw/?s=FQ

                        第01週      第02週      第03週      第04週      第05週

                       第06週      第07週      第08週      第09週      第10週

重點0-2元宇宙文化藝術創作競賽

VR競賽網站    https://www.lkjh.tp.edu.tw/ischool/publish_page/146/

AR競賽網站    https://sites.google.com/jajh.tp.edu.tw/trmetc-ar/

重點0-1中文打字

靜思語67篇    https://contest.hlc.edu.tw/typing/content.asp?lang=3

中文打字18篇

本日重點

Python繪製函數圖形、二個函數圖形、解聯立方程式。

重點1繪製函數圖形

1.使用魔術指令%pylab inline作為開端

► 參考程式(1):

%pylab inline
def f(x): #定義函數 return 2 * x**2 + 3 * x - 5 x = linspace(-4, 4, 200) y = f(x)
plot(x, y)

重點2繪製兩直線

1.繪製二個函數圖形

► 參考程式(2):

%pylab inline
x = arange(-6, 6)
y1 = 1/2 * x + 1/2
y2 = -2 * x + 3
plot(x, y1) #繪圖
plot(x, y2)
grid()

重點3解聯立方程式

1.一元一次方程式

► 參考程式(3):

import numpy as a
b = a.roots([1, 2]) #x + 2 = 0
print(b) #-2

2.一元二次方程式

► 參考程式(4):

import numpy as a
b = a.roots([1, -4, 12]) #x**2 - 4 * x - 12 = 0
print(b) #6, -2

3.解三元一次聯立方程式

┌x + y - z = -2

│x +      z = 2

└x - y +2z = 5

► 參考程式(5):

import numpy as a

c = a.array([[1, 1, -1], [1, 0, 1], [1, -1, 2]])
d = a.array([-2, 2, 5])
ans = a.linalg.solve(c, d)
print(ans) #1, -2, 1

重點4海龍公式

1.求A(1, 5)、B(6, 3)、C(3, -1)三點圍成三角形的面積

► 參考程式(5):

import numpy as np

x = [1, 6, 3] # x座標,A, B, C順序
y = [5, 3, -1] # y座標,A, B, C順序

a = sqrt((x[1] - x[0])**2 + (y[1] - y[0])**2) #邊AB的長度
b = sqrt((x[2] - x[1])**2 + (y[2] - y[1])**2) #邊BC的長度
c = sqrt((x[2] - x[0])**2 + (y[2] - y[0])**2) #邊AC的長度

s = (a + b + c)/2
ans = sqrt(s*(s - a)*(s - b)*(s - c))
ans

重點5集合問題

1.集合A =  {1, 2}、B = {1, 2, 3, 4}、C = {2, 4, 5}、D = {1, 3, 6},判斷集合相同、子集及交集。

► 參考程式(6):

A = {1, 2}
B = {1, 2, 3, 4}
C = {2, 4, 5}
D = {1, 3, 6}

#判斷集合相同
print(A == B)

#子集
print(A <= D)

#交集
print(A & C)

#聯集
print(C | D)

#差集
print(D - A)

#交集為空集合
print(C & D)

重點6其他

2022年5月15日 星期日

Topic40:Python學習8:動手設計自己的函數

 

重點0AICT愛課思

801請加入課程  https://classroom.google.com/c/NTIxNDI5OTI4MDMy?cjc=4bgv2du 

802請加入課程 https://classroom.google.com/c/NDk1NDE2NTYwNDkx?cjc=dssicbh 

803請加入課程 https://classroom.google.com/c/NTIxNDI5OTI3ODg1?cjc=hn2i6tq 

重點0中文打字

靜思語65篇    https://contest.hlc.edu.tw/typing/content.asp?lang=3

靜思語66篇    https://contest.hlc.edu.tw/typing/content.asp?lang=3

本日重點

Python動手設計自己的函數。

重點1以def (define) 作為定義函數的開端

1.使用def作為定義函數的開端

► 參考程式(1):

def my_function(x): print(x) #需要用到時只要呼叫函數 x = "Hello World!" my_function(x)

重點2使用return回傳

1.可使用return回傳在函數中運算完的內容

► 參考程式(2):

def square(x): x = x**2 return x x = 3 x_sq = square(x) print(x) print(x_sq)

點3定義兩個變數

1.函數中可輸入超過一個以上的變數,但要注意的是順序有差別。

► 參考程式(3):

def pairs(x, y): return x - y print(pairs(8, 3)) print(pairs(3, 8))

重點4定義因數個數的函數

► 參考程式(4):

def factor(x): print(x, "的因數有:") for i in range(1, x+1): if x % i == 0: print(i, end =", ") num = int(input("請輸入正整數:")) factor(num)

重點5定義函數算三角形面積

► 參考程式(5):

def triangle(a,h): return 0.5*a*h a = float(input("請輸入三角形的底:")) h = float(input("請輸入三角形的高:")) print("三角形面積 = ", triangle(a, h))

重點6定義函數算三角形面積

► 參考程式(5):

import math
def area(r):
a = math.pi*r**2 return a

def volume(r):
v = (4/3)*math.pi*r**3 return v
r = int(input("請輸入半徑:"))
print("半徑為", "r", "的圓面積 = ", area(r))
print("半徑為", "r", "的球體積 = ", volume(r))


2022年5月8日 星期日

Topic39:Python學習7:迴圈控制有continue、break

 


重點0中文打字

靜思語64篇    https://contest.hlc.edu.tw/typing/content.asp?lang=3

本日重點

Python迴圈程式往往需要適當的依條件中止迴圈,本文以三角形3邊長輸入為例,介紹如何利用break及continue語句,設計編碼不符時可結束輸入或者錯誤超過三次的處理機制。

 Python中的天使與魔王:continue、break

重點1迴圈中的魔王:break

1.在迴圈裡遇到break,它就會說:「你,現在,給我立刻滾出這個迴圈!」

2.break可以讓你跳出圈圈,不管你已經跑在迴圈的哪個位置,它絕對會讓你「立刻跳出迴圈」,執行下一個程式區塊。

► 參考程式(1):

while True:     user = input("媽媽,母親節快樂!!")     if user == "停":         break     print(user) print("好,我不說!!")


► 參考程式(2):

for i in range(1, 21): if i % 6 == 0: break print(i, end=", ")


► 參考程式(3):

t = [-3, 2, 3, 7, 15, 16, 19, 22, 28, 33, 37, 41, 42] for i in t: if i >= 30: break print(i, end=", ")


重點2迴圈中的魔王:continue

1.在迴圈裡遇到continue,它就會說:「嗨!我們再玩一次迴圈吧!」

2.continue不會讓你跳出迴圈雖然它跟break魔王一樣都是打斷你繞圈圈,但continue會再帶你「回到迴圈的起點」,繼續繞下一次的迴圈。

► 參考程式(4):

while True: user = input("媽媽,母親節快樂!!") if user == "停": break if user == "什麼": cuntinue print(user) print("好,我不說!!")

► 參考程式(5):

for i in range(1, 21): if i % 6 == 0: cuntinue print(i, end=", ")


2022年5月1日 星期日

Topic38:Python學習6_三角形面積

 

重點1三角形面積

等海龍公式(Heron's formula),由古希臘數學家亞歷山卓的海龍發現,並在其於公元60年所著的《Metrica》中載有數學證明,原理是利用三角形的三條邊長求取三角形面積。

題目:已知三角形三邊長度,計算三形面積

 ► 參考程式1:求三角形面積

# 三角形面積的計算
a = float(input("輸入三角形第一邊長:")) b = float(input("輸入三角形第二邊長:")) c = float(input("輸入三角形第三邊長:")) s = (a + b + c) / 2 area = (s * (s - a) * (s - b) * (s - c)) ** 0.5 print("三角形面積為:%d" %area)

def getPolygonArea(points): ''' 簡介:用頂點坐標計算多邊形面積 參考:https://blog.csdn.net/qq_38862691/article/details/87886871 參數點:列表,輸入頂點坐標 返回:浮點數,多邊形區域 brief: calculate the Polygon Area with vertex coordinates refer: https://blog.csdn.net/qq_38862691/article/details/87886871 :param points: list, input vertex coordinates :return: float, polygon area ''' sizep = len(points) if sizep<3: return 0.0 area = points[-1][0] * points[0][1] - points[0][0] * points[-1][1] for i in range(1, sizep): v = i - 1 area += (points[v][0] * points[i][1]) area -= (points[i][0] * points[v][1]) return abs(0.5 * area)

► 說明: